mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
confgi: fix []interface parsing issue
This commit is contained in:
parent
9127913370
commit
c9f5d51556
|
@ -17,8 +17,8 @@ reportPnL:
|
|||
- "BNBUSDT"
|
||||
of: binance
|
||||
when:
|
||||
- @daily
|
||||
- @hourly
|
||||
- "@daily"
|
||||
- "@hourly"
|
||||
|
||||
sessions:
|
||||
max:
|
||||
|
|
|
@ -18,13 +18,7 @@ type SingleExchangeStrategyConfig struct {
|
|||
|
||||
type StringSlice []string
|
||||
|
||||
func (s *StringSlice) UnmarshalJSON(b []byte) (err error) {
|
||||
var a interface{}
|
||||
err = json.Unmarshal(b, &a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StringSlice) decode(a interface{}) error {
|
||||
switch d := a.(type) {
|
||||
case string:
|
||||
*s = append(*s, d)
|
||||
|
@ -32,11 +26,28 @@ func (s *StringSlice) UnmarshalJSON(b []byte) (err error) {
|
|||
case []string:
|
||||
*s = append(*s, d...)
|
||||
|
||||
default:
|
||||
err = errors.New("unexpected type for StringSlice")
|
||||
case []interface{}:
|
||||
for _, de := range d {
|
||||
if err := s.decode(de); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return errors.Errorf("unexpected type %T for StringSlice: %+v", d, d)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StringSlice) UnmarshalJSON(b []byte) error {
|
||||
var a interface{}
|
||||
var err = json.Unmarshal(b, &a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.decode(a)
|
||||
}
|
||||
|
||||
type PnLReporter struct {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
_ "github.com/c9s/bbgo/pkg/strategy/buyandhold"
|
||||
)
|
||||
|
||||
func TestLoadStrategies(t *testing.T) {
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
type args struct {
|
||||
configFile string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user