Files
platform/web/routes.go

252 lines
7.9 KiB
Go
Raw Normal View History

2025-03-15 16:07:45 +08:00
package web
2025-03-18 10:13:57 +08:00
import (
"platform/pkg/env"
auth2 "platform/web/auth"
2025-03-18 17:57:07 +08:00
"platform/web/handlers"
"time"
q "platform/web/queries"
2025-03-18 17:57:07 +08:00
2025-03-18 10:13:57 +08:00
"github.com/gofiber/fiber/v2"
)
2025-03-15 16:07:45 +08:00
2025-03-18 17:57:07 +08:00
func ApplyRouters(app *fiber.App) {
api := app.Group("/api")
userRouter(api)
adminRouter(api)
clientRouter(api)
2025-03-18 17:57:07 +08:00
// 回调
callbacks := app.Group("/callback")
callbacks.Get("/identify", handlers.IdentifyCallbackNew)
// 临时
if env.RunMode == env.RunModeDev {
debug := app.Group("/debug")
debug.Get("/sms/:phone", handlers.DebugGetSmsCode)
debug.Get("/iden/clear/:phone", handlers.DebugIdentifyClear)
debug.Get("/session/now", func(ctx *fiber.Ctx) error {
rs, err := q.Session.Where(q.Session.AccessTokenExpires.Gt(time.Now())).Find()
if err != nil {
return err
}
return ctx.JSON(rs)
})
}
}
// 用户接口路由
func userRouter(api fiber.Router) {
// 认证
2025-03-18 17:57:07 +08:00
auth := api.Group("/auth")
auth.Get("/authorize", auth2.AuthorizeGet)
auth.Post("/authorize", auth2.AuthorizePost)
auth.Post("/token", auth2.Token)
auth.Post("/revoke", auth2.Revoke)
auth.Post("/introspect", auth2.Introspect)
2025-03-15 16:07:45 +08:00
// 用户
user := api.Group("/user")
user.Post("/update", handlers.UpdateUser)
user.Post("/update/account", handlers.UpdateAccount)
user.Post("/update/password", handlers.UpdatePassword)
user.Post("/identify", handlers.Identify)
2025-04-08 09:35:19 +08:00
// 白名单
whitelist := api.Group("/whitelist")
whitelist.Post("/list", handlers.ListWhitelist)
whitelist.Post("/create", handlers.CreateWhitelist)
whitelist.Post("/update", handlers.UpdateWhitelist)
whitelist.Post("/remove", handlers.RemoveWhitelist)
2025-04-01 10:51:32 +08:00
// 套餐
resource := api.Group("/resource")
resource.Post("/all", handlers.AllActiveResource)
resource.Post("/list/short", handlers.PageResourceShort)
resource.Post("/list/long", handlers.PageResourceLong)
resource.Post("/create", handlers.CreateResource)
resource.Post("/statistics/free", handlers.StatisticResourceFree)
resource.Post("/statistics/usage", handlers.StatisticResourceUsage)
// 批次
batch := api.Group("/batch")
batch.Post("/page", handlers.PageBatch)
// 通道
channel := api.Group("/channel")
channel.Post("/list", handlers.ListChannel)
channel.Post("/create", handlers.CreateChannel)
// 交易
trade := api.Group("/trade")
trade.Post("/create", handlers.TradeCreate)
trade.Post("/complete", handlers.TradeComplete)
trade.Post("/cancel", handlers.TradeCancel)
trade.Get("/check", handlers.TradeCheck)
// 账单
bill := api.Group("/bill")
bill.Post("/list", handlers.ListBill)
// 公告
announcement := api.Group("/announcement")
announcement.Post("/list", handlers.ListAnnouncements)
// 网关
proxy := api.Group("/proxy")
proxy.Post("/online", handlers.ProxyReportOnline)
proxy.Post("/offline", handlers.ProxyReportOffline)
proxy.Post("/update", handlers.ProxyReportUpdate)
// 节点
edge := api.Group("/edge")
edge.Post("/assign", handlers.AssignEdge)
edge.Post("/all", handlers.AllEdgesAvailable)
2025-12-22 17:31:31 +08:00
// 前台
2025-12-18 14:22:56 +08:00
inquiry := api.Group("/inquiry")
inquiry.Post("/create", handlers.CreateInquiry)
2026-04-14 15:06:08 +08:00
// 产品
product := api.Group("/product")
product.Post("/list", handlers.AllProduct)
2026-04-15 16:56:24 +08:00
// 认证
verify := api.Group("/verify")
verify.Post("/sms/password", handlers.SendSmsCodeForPassword)
}
2025-12-18 14:22:56 +08:00
// 客户端接口路由
func clientRouter(api fiber.Router) {
client := api
// 验证短信令牌
2026-04-15 16:56:24 +08:00
client.Post("/verify/sms", handlers.SendSmsCode)
// 套餐定价查询
resource := client.Group("/resource")
resource.Post("/price", handlers.ResourcePrice)
// 通道管理
channel := client.Group("/channel")
channel.Post("/remove", handlers.RemoveChannels)
}
// 管理员接口路由
func adminRouter(api fiber.Router) {
api = api.Group("/admin")
2025-12-05 18:57:52 +08:00
// admin 管理员
var admin = api.Group("/admin")
admin.Post("/all", handlers.AllAdminByAdmin)
admin.Post("/page", handlers.PageAdminByAdmin)
admin.Post("/create", handlers.CreateAdmin)
admin.Post("/update", handlers.UpdateAdmin)
admin.Post("/remove", handlers.RemoveAdmin)
2026-03-18 18:09:32 +08:00
// admin-role 管理员角色
var adminRole = api.Group("/admin-role")
adminRole.Post("/list", handlers.AllAdminRoleByAdmin)
adminRole.Post("/page", handlers.PageAdminRoleByAdmin)
2026-03-18 18:09:32 +08:00
adminRole.Post("/create", handlers.CreateAdminRole)
adminRole.Post("/update", handlers.UpdateAdminRole)
adminRole.Post("/remove", handlers.RemoveAdminRole)
// permission 权限
var permission = api.Group("/permission")
permission.Post("/list", handlers.AllPermissionByAdmin)
permission.Post("/page", handlers.PagePermissionByAdmin)
2026-03-18 18:09:32 +08:00
// user 用户
var user = api.Group("/user")
user.Post("/page", handlers.PageUserByAdmin)
user.Post("/page/not-bind", handlers.PageUserNotBindByAdmin)
user.Post("/get", handlers.GetUserByAdmin)
user.Post("/create", handlers.CreateUserByAdmin)
user.Post("/update", handlers.UpdateUserByAdmin)
user.Post("/remove", handlers.RemoveUserByAdmin)
user.Post("/update/bind", handlers.BindAdmin)
user.Post("/update/balance", handlers.UpdateUserBalanceByAdmin)
user.Post("/update/balance-inc", handlers.UpdateUserBalanceIncByAdmin)
user.Post("/update/balance-dec", handlers.UpdateUserBalanceDecByAdmin)
// resource 套餐
var resource = api.Group("/resource")
resource.Post("/short/page", handlers.PageResourceShortByAdmin)
resource.Post("/short/page/of-user", handlers.PageResourceShortOfUserByAdmin)
resource.Post("/long/page", handlers.PageResourceLongByAdmin)
resource.Post("/long/page/of-user", handlers.PageResourceLongOfUserByAdmin)
resource.Post("/update", handlers.UpdateResourceByAdmin)
// batch 批次
var batch = api.Group("/batch")
batch.Post("/page", handlers.PageBatchByAdmin)
batch.Post("/page/of-user", handlers.PageBatchOfUserByAdmin)
// channel 通道
var channel = api.Group("/channel")
channel.Post("/page", handlers.PageChannelByAdmin)
channel.Post("/page/of-user", handlers.PageChannelOfUserByAdmin)
2026-04-18 11:15:29 +08:00
// proxy 代理
var proxy = api.Group("/proxy")
proxy.Post("/all", handlers.AllProxyByAdmin)
proxy.Post("/page", handlers.PageProxyByAdmin)
proxy.Post("/create", handlers.CreateProxy)
proxy.Post("/update", handlers.UpdateProxy)
proxy.Post("/update/status", handlers.UpdateProxyStatus)
proxy.Post("/remove", handlers.RemoveProxy)
// trade 交易
var trade = api.Group("/trade")
trade.Post("/page", handlers.PageTradeByAdmin)
trade.Post("/page/of-user", handlers.PageTradeOfUserByAdmin)
trade.Post("/complete", handlers.TradeCompleteByAdmin)
// bill 账单
var bill = api.Group("/bill")
bill.Post("/page", handlers.PageBillByAdmin)
bill.Post("/page/of-user", handlers.PageBillOfUserByAdmin)
2026-04-11 09:51:25 +08:00
// balance-activity 余额变动
var balanceActivity = api.Group("/balance-activity")
balanceActivity.Post("/page", handlers.PageBalanceActivityByAdmin)
balanceActivity.Post("/page/of-user", handlers.PageBalanceActivityOfUserByAdmin)
// product 产品
var product = api.Group("/product")
product.Post("/all", handlers.AllProductByAdmin)
product.Post("/create", handlers.CreateProduct)
product.Post("/update", handlers.UpdateProduct)
product.Post("/remove", handlers.DeleteProduct)
product.Post("/sku/all", handlers.AllProductSkuByAdmin)
product.Post("/sku/page", handlers.PageProductSkuByAdmin)
product.Post("/sku/create", handlers.CreateProductSku)
product.Post("/sku/update", handlers.UpdateProductSku)
2026-04-07 13:22:37 +08:00
product.Post("/sku/update/status", handlers.UpdateProductStatusSku)
product.Post("/sku/remove", handlers.DeleteProductSku)
product.Post("/sku/update/discount/batch", handlers.BatchUpdateProductSkuDiscount)
// discount 折扣
var discount = api.Group("/discount")
discount.Post("/all", handlers.AllDiscountByAdmin)
discount.Post("/page", handlers.PageDiscountByAdmin)
discount.Post("/create", handlers.CreateDiscount)
discount.Post("/update", handlers.UpdateDiscount)
discount.Post("/remove", handlers.DeleteDiscount)
// coupon 优惠券
var coupon = api.Group("/coupon")
coupon.Post("/all", handlers.AllCouponByAdmin)
coupon.Post("/page", handlers.PageCouponByAdmin)
coupon.Post("/create", handlers.CreateCoupon)
coupon.Post("/update", handlers.UpdateCoupon)
coupon.Post("/remove", handlers.DeleteCoupon)
2025-03-15 16:07:45 +08:00
}