mirror of
https://github.com/vx3r/wg-gen-web.git
synced 2025-09-11 12:24:27 +00:00
Integrate https://github.com/jamescun/wg-api stats into the UI
This commit is contained in:
44
api/v1/status/status.go
Normal file
44
api/v1/status/status.go
Normal file
@ -0,0 +1,44 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/core"
|
||||
)
|
||||
|
||||
// ApplyRoutes applies router to gin Router
|
||||
func ApplyRoutes(r *gin.RouterGroup) {
|
||||
g := r.Group("/status")
|
||||
{
|
||||
g.GET("/interface", readInterfaceStatus)
|
||||
g.GET("/clients", readClientStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func readInterfaceStatus(c *gin.Context) {
|
||||
status, err := core.ReadInterfaceStatus()
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"err": err,
|
||||
}).Error("failed to read interface status")
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, status)
|
||||
}
|
||||
|
||||
func readClientStatus(c *gin.Context) {
|
||||
status, err := core.ReadClientStatus()
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"err": err,
|
||||
}).Error("failed to read client status")
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, status)
|
||||
}
|
Reference in New Issue
Block a user