@@ -9,27 +9,36 @@ import (
99type APIController struct {
1010 BaseController
1111 inboundController * InboundController
12+ serverController * ServerController
1213 Tgbot service.Tgbot
1314}
1415
15- func NewAPIController (g * gin.RouterGroup ) * APIController {
16- a := & APIController {}
16+ func NewAPIController (g * gin.RouterGroup , s * ServerController ) * APIController {
17+ a := & APIController {
18+ serverController : s ,
19+ }
1720 a .initRouter (g )
1821 return a
1922}
2023
2124func (a * APIController ) initRouter (g * gin.RouterGroup ) {
22- g = g .Group ("/xui/API/inbounds" )
23- g .Use (a .checkLogin )
25+ api := g .Group ("/xui/API" )
26+ api .Use (a .checkLogin )
27+
28+ a .inboundApi (api )
29+ a .serverApi (api )
30+ }
2431
25- a .inboundController = NewInboundController (g )
32+ func (a * APIController ) inboundApi (api * gin.RouterGroup ) {
33+ inboundsApi := api .Group ("/inbounds" )
34+
35+ a .inboundController = & InboundController {}
2636
2737 inboundRoutes := []struct {
2838 Method string
2939 Path string
3040 Handler gin.HandlerFunc
3141 }{
32- {"GET" , "/createbackup" , a .createBackup },
3342 {"GET" , "/" , a .inboundController .getInbounds },
3443 {"GET" , "/get/:id" , a .inboundController .getInbound },
3544 {"GET" , "/getClientTraffics/:email" , a .inboundController .getClientTraffics },
@@ -48,7 +57,37 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
4857 }
4958
5059 for _ , route := range inboundRoutes {
51- g .Handle (route .Method , route .Path , route .Handler )
60+ inboundsApi .Handle (route .Method , route .Path , route .Handler )
61+ }
62+ }
63+
64+ func (a * APIController ) serverApi (api * gin.RouterGroup ) {
65+ serverApi := api .Group ("/server" )
66+
67+ serverRoutes := []struct {
68+ Method string
69+ Path string
70+ Handler gin.HandlerFunc
71+ }{
72+ {"GET" , "/status" , a .serverController .status },
73+ {"GET" , "/getDb" , a .serverController .getDb },
74+ {"GET" , "/createbackup" , a .createBackup },
75+ {"GET" , "/getConfigJson" , a .serverController .getConfigJson },
76+ {"GET" , "/getXrayVersion" , a .serverController .getXrayVersion },
77+ {"GET" , "/getNewVlessEnc" , a .serverController .getNewVlessEnc },
78+ {"GET" , "/getNewX25519Cert" , a .serverController .getNewX25519Cert },
79+ {"GET" , "/getNewmldsa65" , a .serverController .getNewmldsa65 },
80+
81+ {"POST" , "/getNewEchCert" , a .serverController .getNewEchCert },
82+ {"POST" , "/importDB" , a .serverController .importDB },
83+ {"POST" , "/stopXrayService" , a .serverController .stopXrayService },
84+ {"POST" , "/restartXrayService" , a .serverController .restartXrayService },
85+ {"POST" , "/installXray/:version" , a .serverController .installXray },
86+ {"POST" , "/logs/:count" , a .serverController .getLogs },
87+ }
88+
89+ for _ , route := range serverRoutes {
90+ serverApi .Handle (route .Method , route .Path , route .Handler )
5291 }
5392}
5493
0 commit comments