mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-19 07:15:48 +00:00
[sub] add backend
This commit is contained in:
40
web/controller/sub.go
Normal file
40
web/controller/sub.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"x-ui/web/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SUBController struct {
|
||||
BaseController
|
||||
|
||||
subService service.SubService
|
||||
}
|
||||
|
||||
func NewSUBController(g *gin.RouterGroup) *SUBController {
|
||||
a := &SUBController{}
|
||||
a.initRouter(g)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *SUBController) initRouter(g *gin.RouterGroup) {
|
||||
g = g.Group("/sub")
|
||||
|
||||
g.GET("/:subid", a.subs)
|
||||
}
|
||||
|
||||
func (a *SUBController) subs(c *gin.Context) {
|
||||
subId := c.Param("subid")
|
||||
host := c.Request.Host
|
||||
subs, err := a.subService.GetSubs(subId, host)
|
||||
result := ""
|
||||
for _, sub := range subs {
|
||||
result += sub + "\n"
|
||||
}
|
||||
if err != nil {
|
||||
c.String(400, "Error!")
|
||||
} else {
|
||||
c.String(200, result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user