wireguard-dashboard/http/router/root.go

53 lines
1000 B
Go
Raw Normal View History

2024-07-05 14:41:35 +08:00
package router
import (
"github.com/gin-gonic/gin"
"wireguard-ui/config"
2024-07-05 14:41:35 +08:00
)
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())
2024-08-06 14:49:05 +08:00
//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
// },
//}))
2024-07-05 14:41:35 +08:00
if config.Config.File.Type == "local" {
r.Static("/assets", config.Config.File.Path)
}
2024-07-05 14:41:35 +08:00
for _, opt := range options {
opt(r.Group("api"))
}
return r
}
func Rooters() {
includeRouters(
LoginApi,
UserApi,
ClientApi,
2024-07-11 16:06:52 +08:00
SettingApi,
2024-08-08 17:26:50 +08:00
DashboardApi,
2024-07-05 14:41:35 +08:00
)
}