26 lines
395 B
Go
26 lines
395 B
Go
|
package route
|
||
|
|
||
|
import "github.com/gin-gonic/gin"
|
||
|
|
||
|
type Option func(engine *gin.Engine)
|
||
|
|
||
|
var options []Option
|
||
|
|
||
|
func IncludeRouters(opts ...Option) {
|
||
|
options = append(options, opts...)
|
||
|
}
|
||
|
|
||
|
func InitRouter() *gin.Engine {
|
||
|
r := gin.New()
|
||
|
// 开启IP 追踪
|
||
|
r.ForwardedByClientIP = true
|
||
|
// 将请求打印至控制台
|
||
|
r.Use(gin.Logger())
|
||
|
|
||
|
for _, opt := range options {
|
||
|
opt(r)
|
||
|
}
|
||
|
|
||
|
return r
|
||
|
}
|