gin框架中集成pprof
这里说的是以http的方式集成,如果是非http的方式,那你在任何地方添加代码都可以。
在gin框架中集成pprof首先要引入包_ "net/http/pprof"
。
之后有两种方式,第一种是新监听另一个端口作为pprof http
go func() {
log.Println(http.ListenAndServe(":6060", nil))
}()
第二种是共用服务的端口,这里需要修改路由注册方式
go get https://github.com/gin-contrib/pprof
package main
import (
"net/http"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
)
func main() {
app := gin.Default()
pprof.Register(app) // 性能
app.GET("/test", func(c *gin.Context) {
c.String(http.StatusOK, "test")
})
app.Run(":3000")
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- ryyc.cn 版权所有 湘ICP备2023022495号-3
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务