53 lines
1000 B
Go
53 lines
1000 B
Go
package router
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"wireguard-ui/config"
|
|
)
|
|
|
|
type Option func(engine *gin.RouterGroup)
|
|
|
|
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())
|
|
//r.Use(cors.New(cors.Config{
|
|
// AllowOrigins: []string{"http://localhost:3100"},
|
|
// AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
|
|
// AllowHeaders: []string{"Origin"},
|
|
// ExposeHeaders: []string{"Content-Length"},
|
|
// AllowCredentials: true,
|
|
// AllowOriginFunc: func(origin string) bool {
|
|
// return true
|
|
// },
|
|
//}))
|
|
|
|
if config.Config.File.Type == "local" {
|
|
r.Static("/assets", config.Config.File.Path)
|
|
}
|
|
|
|
for _, opt := range options {
|
|
opt(r.Group("api"))
|
|
}
|
|
|
|
return r
|
|
}
|
|
|
|
func Rooters() {
|
|
includeRouters(
|
|
LoginApi,
|
|
UserApi,
|
|
ClientApi,
|
|
SettingApi,
|
|
DashboardApi,
|
|
)
|
|
}
|