add config app
This commit is contained in:
parent
fd02cfdfc3
commit
3c7838b10a
1
admin.go
1
admin.go
@ -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
24
api.go
@ -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",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
17
config.go
17
config.go
@ -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")
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user