Skip to content

Commit

Permalink
chore: guard switch against duplicate cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Nov 27, 2023
1 parent e17adc2 commit 36945ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions provider/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func NewSwitchFromConfig(other map[string]interface{}) (Provider, error) {
return nil, err
}

cases := make(map[string]struct{})
for _, c := range cc.Switch {
if _, ok := cases[c.Case]; ok {
return nil, fmt.Errorf("switch: duplicate case: %s", c.Case)
}
cases[c.Case] = struct{}{}
}

o := &switchProvider{
cases: cc.Switch,
dflt: cc.Default,
Expand Down

0 comments on commit 36945ba

Please sign in to comment.