-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
googege
committed
Mar 16, 2019
1 parent
22e967d
commit 93b6522
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## 如果开发一个gin中间件 | ||
|
||
[具体看代码](./ginMiddlewareDemo.go) | ||
|
||
所以说 gin的中间件原理就是,每一次的handle动作,都会通过中间件(你设置中间件的前提下), | ||
|
||
要想设置中间件,只需要符合 func(*gin.Context) 即可。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// 测试,开发一个关于gin的一个中间件 | ||
func main() { | ||
engin := gin.Default() | ||
engin.Use(hui) | ||
engin.GET("/", func(context *gin.Context) { | ||
fmt.Println("/") | ||
}) | ||
engin.GET("/test", func(context *gin.Context) { | ||
fmt.Println("/test") | ||
}) | ||
engin.Run(":8080") | ||
} | ||
|
||
|
||
func hui(ctx *gin.Context){ | ||
fmt.Println("我来测试一下,所有的输出全部都会经过这一层,然后输出我这一句话:😝") | ||
} | ||
|
||
|
||
|
||
//我来测试一下,所有的输出全部都会经过这一层,然后输出我这一句话:😝 | ||
/// | ||
//[GIN] 2019/03/16 - 10:19:37 | 200 | 30.598µs | ::1 | GET / | ||
//我来测试一下,所有的输出全部都会经过这一层,然后输出我这一句话:😝 | ||
//[GIN] 2019/03/16 - 10:19:37 | 404 | 38.884µs | ::1 | GET /favicon.ico | ||
//我来测试一下,所有的输出全部都会经过这一层,然后输出我这一句话:😝 | ||
///test | ||
//[GIN] 2019/03/16 - 10:19:50 | 200 | 33.662µs | ::1 | GET /test | ||
//我来测试一下,所有的输出全部都会经过这一层,然后输出我这一句话:😝 | ||
//[GIN] 2019/03/16 - 10:20:02 | 404 | 29.198µs | ::1 | GET /d | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ go tool trace更适合于找出程序在一段时间内正在做什么,而不 | |
如上 | ||
|
||
我将使用一个我实际开发的案例来分析如何运用以上的工具来进行具体的数据分析,静待更新吧。 | ||
|