Simple and easy go web micro framework
Simple and easy go web micro framework
注意:Go 1.23 及以下版本存在标准库安全漏洞,建议使用 Go 1.24 或更高版本。
Document: https://www.kancloud.cn/devfeel/dotweb/346608
Guide: https://github.com/devfeel/dotweb/blob/master/docs/GUIDE.md
go get github.com/devfeel/dotwebpackage main
import (
"fmt"
"github.com/devfeel/dotweb"
)
func main() {
//init DotApp
app := dotweb.New()
//set log path
app.SetLogPath("/home/logs/wwwroot/")
//set route
app.HttpServer.GET("/index", func(ctx dotweb.Context) error{
return ctx.WriteString("welcome to my first web!")
})
//begin server
fmt.Println("dotweb.StartServer begin")
err := app.StartServer(80)
fmt.Println("dotweb.StartServer error => ", err)
}
DotWeb | 1.9.2 | 16core16G | | | | | | | | | | | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min | Max | Error% | Throughput | Received KB/Sec | Send KB/Sec 40% | 39M | 15228356 | 19 | 4 | 43 | 72 | 204 | 0 | 2070 | 0.00% | 48703.47 | 7514.79 | 8656.28 40% | 42M | 15485189 | 18 | 4 | 41 | 63 | 230 | 0 | 3250 | 0.00% | 49512.99 | 7639.7 | 8800.16 40% | 44M | 15700385 | 18 | 3 | 41 | 64 | 233 | 0 | 2083 | 0.00% | 50203.32 | 7746.22 | 8922.86 | | | | | | | | | | | | | ECHO | 1.9.2 | 16core16G | | | | | | | | | | | cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min | Max | Error% | Throughput | Received KB/Sec | Send KB/Sec 38% | 35M | 15307586 | 19 | 4 | 44 | 76 | 181 | 0 | 1808 | 0.00% | 48951.22 | 6166.71 | 9034.94 36% | 35M | 15239058 | 19 | 4 | 45 | 76 | 178 | 0 | 2003 | 0.00% | 48734.26 | 6139.37 | 8994.9 37% | 37M | 15800585 | 18 | 3 | 41 | 66 | 229 | 0 | 2355 | 0.00% | 50356.09 | 6343.68 | 9294.24 | | | | | | | | | | | | | Gin | 1.9.2 | 16core16G | | | | | | | | | | | cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min | Max | Error% | Throughput | Received KB/Sec | Send KB/Sec 36% | 36M | 15109143 | 19 | 6 | 44 | 71 | 175 | 0 | 3250 | 0.00% | 48151.87 | 5877.91 | 8746.33 36% | 40M | 15255749 | 19 | 5 | 43 | 70 | 189 | 0 | 3079 | 0.00% | 48762.53 | 5952.45 | 8857.25 36% | 40M | 15385401 | 18 | 4 | 42 | 66 | 227 | 0 | 2312 | 0.00% | 49181.03 | 6003.54 | 8933.27
…接受两个参数,一个是URI路径,另一个是 HttpHandle 类型,设定匹配到该路径时执行的方法;
静态路由语法就是没有任何参数变量,pattern是一个固定的字符串。
package main
import (
"github.com/devfeel/dotweb"
)
func main() {
dotapp := dotweb.New()
dotapp.HttpServer.GET("/hello", func(ctx dotweb.Context) error{
return ctx.WriteString("hello world!")
})
dotapp.StartServer(80)
}test: curl http://127.0.0.1/hello
参数路由以冒号 : 后面跟一个字符串作为参数名称,可以通过 HttpContext的 GetRouterName 方法获取路由参数的值。
package main
import (
"github.com/devfeel/dotweb"
)
func main() {
dotapp := dotweb.New()
dotapp.HttpServer.GET("/hello/:name", func(ctx dotweb.Context) error{
return ctx.WriteString("hello " + ctx.GetRouterName("name"))
})
dotapp.HttpServer.GET("/news/:category/:newsid", func(ctx dotweb.Context) error{
category := ctx.GetRouterName("category")
newsid := ctx.GetRouterName("newsid")
return ctx.WriteString("news info: category=" + category + " newsid=" + newsid)
})
dotapp.StartServer(80)
}test:
curl http://127.0.0.1/hello/devfeel
curl http://127.0.0.1/hello/category1/1
g := server.Group("/user")
g.GET("/", Index)
g.GET("/profile", Profile)test:
curl http://127.0.0.1/user
curl http://127.0.0.1/user/profile
type UserInfo struct {
UserName string `form:"user"`
Sex int `form:"sex"`
}
func TestBind(ctx dotweb.HttpContext) error{
user := new(UserInfo)
if err := ctx.Bind(user); err != nil {
return ctx.WriteString("err => " + err.Error())
}else{
return ctx.WriteString("TestBind " + fmt.Sprint(user))
}
}
…HttpServer.EnabledSession
设置是否开启Session支持,目前支持runtime、redis两种模式,默认不开启
HttpServer.EnabledGzip
设置是否开启Gzip支持,默认不开启
HttpServer.EnabledListDir
设置是否启用目录浏览,仅对Router.ServerFile有效,若设置该项,则可以浏览目录文件,默认不开启
HttpServer.EnabledAutoHEAD
设置是否自动启用Head路由,若设置该项,则会为除Websocket\HEAD外所有路由方式默认添加HEAD路由,非开发模式默认不开启
HttpServer.EnabledAutoOPTIONS
设置是否自动启用Options路由,若设置该项,则会为除Websocket\HEAD外所有路由方式默认添加OPTIONS路由,非开发模式默认不开启
HttpServer.EnabledIgnoreFavicon
设置是否忽略Favicon的请求,一般用于接口项目
HttpServer.EnabledDetailRequestData
设置是否启用详细请求数据统计,默认为false,若设置该项,将启用ServerStateInfo中DetailRequestUrlData的统计
HttpServer.EnabledTLS
设置是否启用TLS加密处理
HttpServer.EnabledIgnoreFavicon
设置是否忽略favicon响应,默认为false,若设置该项,将会默认注册内集成的IgnoreFaviconModule,在路由生效前执行
HttpServer.EnabledBindUseJsonTag
设置是否启用json tag生效于Bind接口,默认为false,若设置该项,将会在Bind执行时检查json tag
type ExceptionHandle func(Context, error)type NotFoundHandle func(http.ResponseWriter, *http.Request)| Go 版本 | 支持状态 | 说明 |
|---|---|---|
| 1.26.x | ✅ 推荐使用 | 最新稳定版,CI 测试通过 |
| 1.25.x | ✅ 支持 | CI 测试通过 |
| 1.24.x | ✅ 支持 | 最低版本要求,CI 测试通过 |
| < 1.24 | ❌ 不支持 | 存在标准库安全漏洞 |
⚠️ 安全警告:Go 1.23 及以下版本存在以下安全漏洞:
- GO-2026-4341: net/url 内存耗尽
- GO-2026-4340: crypto/tls 握手问题
- GO-2025-4012: net/http cookie 解析
- 等共 12 个漏洞
依赖管理使用 go mod。
项目简介:http长连接网关服务,提供Websocket及长轮询服务
项目简介:基于dotweb与mapper的一款go的博客程序
项目简介:基于dotweb的一款go的Blog(博客)服务端
项目简介:token服务,提供token一致性服务以及相关的全局ID生成服务等
项目简介:微信Access Token中控服务器,用来统一管理各个公众号的access_token,提供统一的接口进行获取和自动刷新Access Token。
项目简介:基于dotweb、dotlog、mapper、dottask、cache、database的综合项目模板。
No open issues yet, or sync has not completed.