3x-ui/web/controller/api.go

42 lines
836 B
Go
Raw Normal View History

2023-02-09 11:18:06 -08:00
package controller
2023-05-18 14:01:05 -07:00
import (
"x-ui/web/service"
"github.com/gin-gonic/gin"
)
2023-02-09 11:18:06 -08:00
2023-04-01 15:00:15 -07:00
type APIController struct {
BaseController
inboundController *InboundController
2025-09-08 16:22:43 -07:00
serverController *ServerController
2023-05-18 14:01:05 -07:00
Tgbot service.Tgbot
2023-02-09 11:18:06 -08:00
}
func NewAPIController(g *gin.RouterGroup) *APIController {
a := &APIController{}
a.initRouter(g)
return a
2023-02-09 11:18:06 -08:00
}
func (a *APIController) initRouter(g *gin.RouterGroup) {
2025-09-08 16:22:43 -07:00
// Main API group
api := g.Group("/panel/api")
api.Use(a.checkLogin)
2023-02-09 11:18:06 -08:00
2025-09-08 16:22:43 -07:00
// Inbounds API
inbounds := api.Group("/inbounds")
a.inboundController = NewInboundController(inbounds)
2025-09-08 16:22:43 -07:00
// Server API
server := api.Group("/server")
a.serverController = NewServerController(server)
2025-09-08 16:22:43 -07:00
// Extra routes
api.GET("/backuptotgbot", a.BackuptoTgbot)
}
2023-05-18 14:01:05 -07:00
2025-09-08 16:22:43 -07:00
func (a *APIController) BackuptoTgbot(c *gin.Context) {
2023-05-20 15:59:27 -07:00
a.Tgbot.SendBackupToAdmins()
2023-05-18 14:01:05 -07:00
}