31 lines
627 B
Go
31 lines
627 B
Go
package ext
|
|
|
|
import (
|
|
"demo-server/internal/config"
|
|
"demo-server/internal/middleware"
|
|
"github.com/gin-contrib/pprof"
|
|
"github.com/gin-gonic/gin"
|
|
"runtime"
|
|
)
|
|
|
|
/*
|
|
我有一个需要根据 go build tags 完成部分功能在编译时刻启用的需求
|
|
所以定义 initFunc 维持服务
|
|
当满足 tags 的时候加入 initEngQueue
|
|
*/
|
|
|
|
type initFunc func(e *gin.Engine)
|
|
|
|
var initEngQueue []initFunc
|
|
|
|
func Init(e *gin.Engine, cfg *config.Configuration) {
|
|
if cfg.Svr.PprofOn {
|
|
runtime.SetMutexProfileFraction(1)
|
|
runtime.SetBlockProfileRate(1)
|
|
pprof.Register(e)
|
|
}
|
|
e.Use(middleware.Cors())
|
|
initEng(e)
|
|
initMetric(e)
|
|
}
|