:toda:
This commit is contained in:
23
http/router/client.go
Normal file
23
http/router/client.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"wireguard-ui/http/api"
|
||||
"wireguard-ui/http/middleware"
|
||||
)
|
||||
|
||||
// ClientApi
|
||||
// @description: 登陆相关API
|
||||
// @param r
|
||||
func ClientApi(r *gin.RouterGroup) {
|
||||
client := r.Group("client", middleware.Authorization())
|
||||
{
|
||||
client.POST("", api.Client().Save) // 新增/编辑客户端
|
||||
client.DELETE("/:id", api.Client().Delete) // 删除客户端
|
||||
client.GET("/list", api.Client().List) // 客户端列表
|
||||
client.POST("/generate-keys", api.Client().GenerateKeys) // 生成客户端密钥
|
||||
client.POST("/generate-ip", api.Client().GenerateIP) // 生成客户端IP
|
||||
client.GET("/download/:id/:type", api.Client().Download) // 下载客户端配置文件
|
||||
}
|
||||
|
||||
}
|
18
http/router/login.go
Normal file
18
http/router/login.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"wireguard-ui/http/api"
|
||||
)
|
||||
|
||||
// LoginApi
|
||||
// @description: 登陆相关API
|
||||
// @param r
|
||||
func LoginApi(r *gin.RouterGroup) {
|
||||
login := r.Group("/login")
|
||||
{
|
||||
login.GET("/captcha", api.Login().Captcha) // 获取登陆验证码
|
||||
login.POST("", api.Login().Login) // 登陆
|
||||
}
|
||||
|
||||
}
|
35
http/router/root.go
Normal file
35
http/router/root.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
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())
|
||||
|
||||
for _, opt := range options {
|
||||
opt(r.Group("api"))
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func Rooters() {
|
||||
includeRouters(
|
||||
LoginApi,
|
||||
UserApi,
|
||||
ClientApi,
|
||||
)
|
||||
}
|
23
http/router/user.go
Normal file
23
http/router/user.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"wireguard-ui/http/api"
|
||||
"wireguard-ui/http/middleware"
|
||||
)
|
||||
|
||||
// UserApi
|
||||
// @description: 用户相关API
|
||||
// @param r
|
||||
func UserApi(r *gin.RouterGroup) {
|
||||
userApi := r.Group("user", middleware.Authorization())
|
||||
{
|
||||
userApi.GET("/info", api.User().GetLoginUser) // 获取当前登陆用户信息
|
||||
userApi.POST("", api.User().SaveUser) // 新增/编辑用户
|
||||
userApi.DELETE("/:id", api.User().Delete) // 删除用户
|
||||
userApi.GET("/list", api.User().List) // 分页列表
|
||||
userApi.PUT("/status/:id", api.User().Status) // 修改用户状态
|
||||
userApi.PUT("/change-password", api.User().ChangePassword) // 修改用户密码
|
||||
userApi.PUT("/reset-password/:id", api.User().ResetPassword) // 重置用户密码
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user