12345678910111213141516171819202122232425262728293031323334353637383940 |
- package utils
- import (
- "github.com/gin-gonic/gin"
- "base-gin/utils/base"
- "base-gin/utils/middleware"
- "base-gin/utils/pprof"
- )
- type BootstrapConf struct {
- LogLevel string
- }
- func Bootstrap(router *gin.Engine, opts BootstrapConf) {
- //环境判断 env GIN_MODE=release/debug
- if base.GetJHYEnv() == base.ENV_PRODUCT {
- gin.SetMode(gin.ReleaseMode)
- }
- //日志配置 json格式,默认标准输出
- base.InitLog(opts.LogLevel)
- // trace init
- base.InitTracer()
- // 中间件
- router.Use(middleware.Tracer())
- router.Use(middleware.Logger())
- router.Use(gin.Recovery())
- //health
- router.HEAD("/health", func(c *gin.Context) {
- c.String(200, "succ")
- })
- //性能分析工具
- if base.IsPprofEnv() {
- pprof.Register(router)
- }
- }
|