Skip to content

Commit fdb6e3d

Browse files
committed
update example/middleware
1 parent 12babb9 commit fdb6e3d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

example/middleware/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@ func main() {
2222
//设置gzip开关
2323
//app.SetEnabledGzip(true)
2424

25-
//设置路由
26-
InitRoute(app.HttpServer)
2725

2826
//InitModule(app)
2927

3028
//app.UseRequestLog()
3129
app.Use(
3230
NewAccessFmtLog("app"),
3331
)
34-
app.ExcludeUse(NewAccessFmtLog("appex"), "/", "/")
32+
exAccessFmtLog := NewAccessFmtLog("appex")
33+
exAccessFmtLog.Exclude("/index")
34+
exAccessFmtLog.Exclude("/v1/machines/queryIP/:IP")
35+
app.Use(exAccessFmtLog)
36+
37+
app.ExcludeUse(NewAccessFmtLog("appex1"), "/")
38+
39+
//设置路由
40+
InitRoute(app.HttpServer)
3541

3642
//启动 监控服务
3743
app.SetPProfConfig(true, 8081)
@@ -50,13 +56,16 @@ func main() {
5056
func Index(ctx dotweb.Context) error {
5157
ctx.Response().Header().Set("Content-Type", "text/html; charset=utf-8")
5258
//fmt.Println(time.Now(), "Index Handler")
53-
err := ctx.WriteString("index => ", fmt.Sprint(ctx.RouterNode().Middlewares()))
59+
err := ctx.WriteString("index => ", ctx.Request().Url())
5460
fmt.Println(ctx.RouterNode().GroupMiddlewares())
5561
return err
5662
}
5763

5864
func InitRoute(server *dotweb.HttpServer) {
5965
server.Router().GET("/", Index)
66+
server.Router().GET("/index", Index)
67+
server.Router().GET("/v1/machines/queryIP/:IP", Index)
68+
server.Router().GET("/v1/machines/queryIP2", Index)
6069
server.Router().GET("/use", Index).Use(NewAccessFmtLog("Router-use"))
6170

6271
g := server.Group("/group").Use(NewAccessFmtLog("group")).Use(NewSimpleAuth("admin"))

0 commit comments

Comments
 (0)