wireguard-dashboard/route/route.go

36 lines
596 B
Go
Raw Permalink Normal View History

2024-03-05 16:59:37 +08:00
package route
2024-05-24 17:31:41 +08:00
import (
"github.com/gin-gonic/gin"
"net/http"
"wireguard-dashboard/web"
)
2024-03-05 16:59:37 +08:00
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())
2024-05-24 17:31:41 +08:00
//r.GET("/", func(c *gin.Context) {
// c.Redirect(http.StatusMovedPermanently, "/web/")
//})
r.StaticFS("/web", http.FS(web.Static))
2024-03-05 16:59:37 +08:00
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
}