From e44910d4a15d2ca4958c4fdca5dd9c7ad23cfb28 Mon Sep 17 00:00:00 2001 From: fiftin Date: Mon, 22 Jul 2024 17:17:45 +0500 Subject: [PATCH] fix(apps): delete options with emply values --- api/apps.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/api/apps.go b/api/apps.go index a5a20ed25..e8822af9b 100644 --- a/api/apps.go +++ b/api/apps.go @@ -174,20 +174,26 @@ func setApp(w http.ResponseWriter, r *http.Request) { options := structToFlatMap(app) for k, v := range options { - if v == nil { - continue - } - t := reflect.TypeOf(v) - switch t.Kind() { - case reflect.Slice, reflect.Array: - newV, err := json.Marshal(v) - if err != nil { - helpers.WriteErrorStatus(w, err.Error(), http.StatusInternalServerError) - return + + if v != nil { + switch t.Kind() { + case reflect.String: + if v == "" { + v = nil + } + case reflect.Slice, reflect.Array: + newV, err := json.Marshal(v) + if err != nil { + helpers.WriteErrorStatus(w, err.Error(), http.StatusInternalServerError) + return + } + v = string(newV) + if v == "[]" { + v = nil + } + default: } - v = string(newV) - default: } if err := setAppOption(store, appID, k, v); err != nil {