api.go 836 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controller
  2. import (
  3. "x-ui/web/service"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type APIController struct {
  7. BaseController
  8. inboundController *InboundController
  9. serverController *ServerController
  10. Tgbot service.Tgbot
  11. }
  12. func NewAPIController(g *gin.RouterGroup) *APIController {
  13. a := &APIController{}
  14. a.initRouter(g)
  15. return a
  16. }
  17. func (a *APIController) initRouter(g *gin.RouterGroup) {
  18. // Main API group
  19. api := g.Group("/panel/api")
  20. api.Use(a.checkLogin)
  21. // Inbounds API
  22. inbounds := api.Group("/inbounds")
  23. a.inboundController = NewInboundController(inbounds)
  24. // Server API
  25. server := api.Group("/server")
  26. a.serverController = NewServerController(server)
  27. // Extra routes
  28. api.GET("/backuptotgbot", a.BackuptoTgbot)
  29. }
  30. func (a *APIController) BackuptoTgbot(c *gin.Context) {
  31. a.Tgbot.SendBackupToAdmins()
  32. }