Skip to content

Commit

Permalink
trim empty subs
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Hailey committed Nov 20, 2020
1 parent 374c92b commit be05ae5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,21 @@ func mergeStringSlices(a []string, b []string) []string {
return a
}

func trimSlice(s []string) []string {
for _, v := range s {
if len(strings.TrimSpace(v)) == 0 {
i := indexOf(s, v)
s = trimSlice(append(s[:i], s[i+1:]...))
}
}
return s
}

func patchEntity(event *types.Event) *EntityPatch {
entity := new(EntityPatch)

// Merge subscriptions
entity.Subscriptions = mergeStringSlices(event.Entity.Subscriptions, plugin.Subscriptions)
entity.Subscriptions = trimSlice(mergeStringSlices(event.Entity.Subscriptions, plugin.Subscriptions))

return entity
}
Expand Down Expand Up @@ -299,9 +309,6 @@ func executeHandler(event *types.Event) error {
} else if resp.StatusCode >= 300 {
log.Fatalf("ERROR: %v %s", resp.StatusCode, http.StatusText(resp.StatusCode))
return err
} else if resp.StatusCode == 204 {
log.Printf("Successfully deleted entity \"%s\" from namespace \"%s\"", event.Entity.Name, event.Entity.Namespace)
return nil
} else {
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
Expand Down

0 comments on commit be05ae5

Please sign in to comment.