-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/god-jason/bucket/config" | ||
"github.com/god-jason/bucket/setting" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// @Summary 查询配置 | ||
// @Schemes | ||
// @Description 查询配置 | ||
// @Tags setting | ||
// @Param module path string true "模块,web database log ..." | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} curd.ReplyData[map[string]any] 返回配置 | ||
// @Router /setting/:module [get] | ||
func settingGet(ctx *gin.Context) { | ||
OK(ctx, viper.GetStringMap(ctx.Param("module"))) | ||
} | ||
|
||
// @Summary 修改配置 | ||
// @Schemes | ||
// @Description 修改配置 | ||
// @Tags setting | ||
// @Param module path string true "模块,web database log ..." | ||
// @Param cfg body map[string]any true "配置内容" | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} curd.ReplyData[int] | ||
// @Router /setting/:module [post] | ||
func settingSet(ctx *gin.Context) { | ||
m := ctx.Param("module") | ||
|
||
var conf map[string]any | ||
err := ctx.ShouldBindJSON(&conf) | ||
if err != nil { | ||
Error(ctx, err) | ||
return | ||
} | ||
for k, v := range conf { | ||
viper.Set(m+"."+k, v) | ||
} | ||
|
||
err = config.Store() | ||
if err != nil { | ||
Error(ctx, err) | ||
return | ||
} | ||
OK(ctx, nil) | ||
} | ||
|
||
// @Summary 查询配置表单 | ||
// @Schemes | ||
// @Description 查询配置表单 | ||
// @Tags setting | ||
// @Param module path string true "模块,web database log ..." | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} curd.ReplyData[Module] 返回配置表单 | ||
// @Router /setting/:module/form [get] | ||
func settingForm(ctx *gin.Context) { | ||
m := ctx.Param("module") | ||
md := setting.Load(m) | ||
if md == nil { | ||
Fail(ctx, "模块不存在") | ||
return | ||
} | ||
OK(ctx, md.Form) | ||
} | ||
|
||
// @Summary 查询所有配置 | ||
// @Schemes | ||
// @Description 查询所有配置 | ||
// @Tags setting | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} curd.ReplyData[[]Module] 返回配置表单 | ||
// @Router /setting/modules [get] | ||
func settingModules(ctx *gin.Context) { | ||
ms := setting.Modules() | ||
OK(ctx, ms) | ||
} | ||
|
||
func init() { | ||
Register("POST", "setting/:module", settingSet) | ||
Register("GET", "setting/:module", settingGet) | ||
Register("GET", "setting/:module/form", settingForm) | ||
Register("GET", "setting/modules", settingModules) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters