add path option for saveConfig API

This commit is contained in:
ginuerzh 2023-11-17 22:24:50 +08:00
parent 2c82233b4f
commit 330631fd79

View File

@ -62,6 +62,9 @@ type saveConfigRequest struct {
// output format, one of yaml|json, default is yaml.
// in: query
Format string `form:"format" json:"format"`
// file path, default is gost.yaml|gost.json in current working directory.
// in: query
Path string `form:"path" json:"path"`
}
// successful operation.
@ -92,6 +95,10 @@ func saveConfig(ctx *gin.Context) {
req.Format = "yaml"
}
if req.Path != "" {
file = req.Path
}
f, err := os.Create(file)
if err != nil {
writeError(ctx, &Error{