75 lines
1.3 KiB
Go
75 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ApiRun(c *gin.Context) {
|
|
cfg.Run()
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "done",
|
|
})
|
|
}
|
|
|
|
func ApiRunApp(c *gin.Context) {
|
|
if _, ok := cfg.apps[c.Param("app")]; ok {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "done",
|
|
})
|
|
}
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "error",
|
|
"error": "no app found",
|
|
})
|
|
}
|
|
|
|
func ApiSave(c *gin.Context) {
|
|
if err := cfg.Save(); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "error",
|
|
"error": err,
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "done",
|
|
})
|
|
}
|
|
}
|
|
|
|
func ApiConfig(c *gin.Context) {
|
|
if b, err := cfg.Pretty(); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "error",
|
|
"error": err,
|
|
})
|
|
} else {
|
|
c.Data(http.StatusOK, "application/json", b)
|
|
}
|
|
}
|
|
|
|
func ApiConfigApp(c *gin.Context) {
|
|
name := c.Param("app")
|
|
found := false
|
|
for _, app := range cfg.Apps {
|
|
if app.Name == name {
|
|
found = true
|
|
if b, err := app.Pretty(); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "error",
|
|
"error": err,
|
|
})
|
|
} else {
|
|
c.Data(http.StatusOK, "application/json", b)
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "error",
|
|
"error": "no app found",
|
|
})
|
|
}
|
|
}
|