Skip to content

Commit

Permalink
Fix JSON flag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Nov 9, 2023
1 parent c6541f2 commit c8ac5fb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/webrtc-load-tester/utils/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"os/signal"
"reflect"
"runtime"
"syscall"

Expand Down Expand Up @@ -55,6 +56,10 @@ func JSONVarFlag(fs *flag.FlagSet, dest interface{}, name, defaultValue, usage s
panic(err)
}
fs.Func(name, usage, func(s string) error {
// Clear any previously set value, including the default above
destVal := reflect.ValueOf(dest).Elem()
destVal.Set(reflect.Zero(destVal.Type()))

return json.Unmarshal([]byte(s), dest)
})
}
Expand Down

0 comments on commit c8ac5fb

Please sign in to comment.