added folders config update
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
de8717dc99
commit
52e767b941
@ -69,6 +69,23 @@ func GetFolders(cfg config.Config) (res []Folder, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InsertOrUpdateFolders ...
|
||||||
|
func InsertOrUpdateFolders(cfg config.Config, folders []Folder) (res string, err error) {
|
||||||
|
var w = Cfg{Key: "folders"}
|
||||||
|
if exists, _ := cfg.Db.Get(&w); exists {
|
||||||
|
resbytes, err := json.Marshal(folders)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
w.Value = string(resbytes)
|
||||||
|
_, err = cfg.Db.ID(w.ID).Update(&w)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type Trustlist struct {
|
type Trustlist struct {
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,15 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
|
|||||||
folders, err := models.GetFolders(*cfg)
|
folders, err := models.GetFolders(*cfg)
|
||||||
return Result(c, err, folders)
|
return Result(c, err, folders)
|
||||||
})
|
})
|
||||||
|
e.POST("/ips/folders", func(c echo.Context) (err error) {
|
||||||
|
var folders []models.Folder
|
||||||
|
err = c.Bind(&folders)
|
||||||
|
if err != nil {
|
||||||
|
return Result(c, err, "Unable to parse JSON")
|
||||||
|
}
|
||||||
|
_, err = models.InsertOrUpdateFolders(*cfg, folders)
|
||||||
|
return Result(c, err, folders)
|
||||||
|
})
|
||||||
|
|
||||||
e.Logger.Fatal(
|
e.Logger.Fatal(
|
||||||
e.Start(
|
e.Start(
|
||||||
|
Loading…
Reference in New Issue
Block a user