Skip to content

Commit

Permalink
fix(apps): delete options with emply values
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jul 22, 2024
1 parent fb75ab4 commit e44910d
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e44910d

Please sign in to comment.