2024-07-05 14:41:35 +08:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-08-21 09:10:01 +08:00
|
|
|
"net/http"
|
2024-07-10 10:51:20 +08:00
|
|
|
"wireguard-ui/config"
|
2024-08-21 09:10:01 +08:00
|
|
|
"wireguard-ui/dist"
|
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-07-10 10:51:20 +08:00
|
|
|
if config.Config.File.Type == "local" {
|
|
|
|
r.Static("/assets", config.Config.File.Path)
|
|
|
|
}
|
|
|
|
|
2024-08-21 09:10:01 +08:00
|
|
|
r.StaticFS("/web", http.FS(dist.Static))
|
|
|
|
|
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
|
|
|
)
|
|
|
|
}
|