Skip to content

Commit

Permalink
refactor(main): 修改example
Browse files Browse the repository at this point in the history
  • Loading branch information
BadKid90s committed Apr 25, 2024
1 parent ca9c7ad commit fa0e60a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/base/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func gzipFun() *knife.Chain {
chain := knife.NewChain().
Use(logger.Logger()).
Use(recover.Recover()).
//Use(middleware.GzipDefault()).
//Use(gzip.Default()).
Use(gzip.Gzip(1024)).
Use(func(context *knife.Context) {
data := "Gzip是一种压缩文件格式并且也是一个在类 Unix 上的一种文件解压缩的软件,通常指GNU计划的实现,此处的gzip代表GNU zip。" +
Expand Down
6 changes: 3 additions & 3 deletions example/matcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ func main() {
chain.Use(recover.Recover())

//添加响应头是否存在匹配器的自定义中间件
chain.UseMatcher(header.HeaderResponseExists("token"), func(context *knife.Context) {
chain.UseMatcher(header.ResponseExists("token"), func(context *knife.Context) {
log.Printf("token middleware,token:%s ", context.Writer.Header().Get("token"))
context.Next()
})

//添加带有组合匹配器的自定义中间件
chain.UseMatcher(combination.Any(header.HeaderResponseExists("token"), header.HeaderResponseExists("auth")), func(context *knife.Context) {
chain.UseMatcher(combination.Any(header.ResponseExists("token"), header.ResponseExists("auth")), func(context *knife.Context) {
log.Printf("token middleware,token:%s ", context.Writer.Header().Get("token"))
context.Next()
})

//添加带路径匹配器的自定义中间件
chain.UseMatcher(path.PathPrefix("/hello"), func(context *knife.Context) {
chain.UseMatcher(path.Prefix("/hello"), func(context *knife.Context) {
log.Println("pathPrefix matcher")
context.Next()
})
Expand Down

0 comments on commit fa0e60a

Please sign in to comment.