2024-03-05 16:59:37 +08:00
|
|
|
package route
|
|
|
|
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
|
2024-03-13 17:05:02 +08:00
|
|
|
type Option func(engine *gin.RouterGroup)
|
2024-03-05 16:59:37 +08:00
|
|
|
|
|
|
|
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 {
|
2024-03-13 17:05:02 +08:00
|
|
|
opt(r.Group("api"))
|
2024-03-05 16:59:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|