Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
googege committed Mar 16, 2019
1 parent 22e967d commit 93b6522
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- [go语言容易错的几个点](https://github.com/googege/blog/tree/master/go/go/important/README.md)
- [go语言的逃逸分析](https://github.com/googege/blog/tree/master/go/go/escape-analysis/README.md)
- [go语言的一些不容易被注意到的但是又很重要的问题](https://github.com/googege/blog/tree/master/go/go/ignore-but-important/README.md)
## go周边
- [gin中间件的开发]()
## 算法和数据结构系列
- [堆和栈的解释](https://github.com/googege/blog/tree/master/algorithm-structure/heap-stack/README.md)
- [树系列结构以及相应的算法](https://github.com/googege/blog/tree/master/algorithm-structure/tree/README.md)[waiting]
Expand Down
7 changes: 7 additions & 0 deletions go/go-surrounding/gin-middleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 如果开发一个gin中间件

[具体看代码](./ginMiddlewareDemo.go)

所以说 gin的中间件原理就是,每一次的handle动作,都会通过中间件(你设置中间件的前提下),

要想设置中间件,只需要符合 func(*gin.Context) 即可。
41 changes: 41 additions & 0 deletions go/go-surrounding/gin-middleware/ginMiddlewareDemo.go
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




1 change: 1 addition & 0 deletions go/tool/performance-testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ go tool trace更适合于找出程序在一段时间内正在做什么,而不
如上

我将使用一个我实际开发的案例来分析如何运用以上的工具来进行具体的数据分析,静待更新吧。

0 comments on commit 93b6522

Please sign in to comment.