add config app

This commit is contained in:
shoopea 2025-10-07 20:56:21 +02:00
parent fd02cfdfc3
commit 3c7838b10a
4 changed files with 46 additions and 4 deletions

View File

@ -51,6 +51,7 @@ func (a *AdminConfig) Run() {
r.GET("/save", ApiSave)
r.GET("/config", ApiConfig)
r.GET("/config/:app", ApiConfigApp)
srv := &http.Server{
Addr: a.Addr,

24
api.go
View File

@ -48,3 +48,27 @@ func ApiConfig(c *gin.Context) {
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",
})
}
}

View File

@ -206,6 +206,23 @@ func (c *Config) Pretty() ([]byte, error) {
return pretty.PrettyOptions(b, &pretty.Options{Indent: " "}), nil
}
// Pretty App Config
func (a *AppConfig) Pretty() ([]byte, error) {
log.WithFields(log.Fields{}).Debugf("starting")
defer log.WithFields(log.Fields{}).Debugf("done")
cfgMx.Lock()
defer cfgMx.Unlock()
b, err := json.Marshal(a)
if err != nil {
log.WithFields(log.Fields{"error": err, "call": "json.Marshal"}).Errorf("")
return nil, err
}
return pretty.PrettyOptions(b, &pretty.Options{Indent: " "}), nil
}
// Save config
func (c *Config) Save() error {
log.WithFields(log.Fields{}).Debugf("starting")

View File

@ -1,7 +1,7 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "6cf9989"
var githash = "fd02cfd"
var branch = "master"
var buildstamp = "2025-10-01_20:30:38"
var commits = "109"
var version = "6cf9989-b109 - 2025-10-01_20:30:38"
var buildstamp = "2025-10-07_18:55:46"
var commits = "110"
var version = "fd02cfd-b110 - 2025-10-07_18:55:46"