0
0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2025-09-10 12:14:28 +00:00
This commit is contained in:
Christoph Haas
2020-10-06 18:14:34 +02:00
parent 8b4038c238
commit 31dd494d62
11 changed files with 534 additions and 3 deletions

44
api/v1/status/status.go Normal file
View 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)
}

View File

@ -5,6 +5,7 @@ import (
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/auth"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/client"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/server"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/status"
)
// ApplyRoutes apply routes to gin router
@ -14,9 +15,9 @@ func ApplyRoutes(r *gin.RouterGroup, private bool) {
if private {
client.ApplyRoutes(v1)
server.ApplyRoutes(v1)
status.ApplyRoutes(v1)
} else {
auth.ApplyRoutes(v1)
}
}
}