Skip to content

Commit

Permalink
ditch reflect, use type switch instead
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Neuroth <pet.v.ne@gmail.com>
  • Loading branch information
grubles and nepet committed Aug 27, 2023
1 parent 4c13d3d commit dfa7ae6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions clightning/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,18 @@ func BitcoinFallbackFromClnConfig(client *ClightningClient) Processor {
if v, ok := plugin.Options["bitcoin-rpcport"]; ok {
if v != nil {
// detect if type is string (CLN < v23.08)
if reflect.TypeOf(v).String() == "string" {
port, err := strconv.Atoi(v.(string))
switch p := v.(type) {
case string:
port, err := strconv.Atoi(p)
if err != nil {
return nil, err
c.Bitcoin.RpcPort = uint(port)
}
} else {
c.Bitcoin.RpcPort = uint(v.(float64))
}
c.Bitcoin.RpcPort = uint(port)
case float64:
c.Bitcoin.RpcPort = uint(p)
default:
return nil, fmt.Errorf("Bitcoind rpcport type %T not handled", v)
}
}
}
}
Expand Down

0 comments on commit dfa7ae6

Please sign in to comment.