From 2611012d289bc7308f08e4c37ebd0e0d856b00b3 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 23 Aug 2022 01:54:29 +0800 Subject: [PATCH] types: move json struct to types package --- pkg/strategy/output.go | 25 +++++++------------------ pkg/types/json.go | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 pkg/types/json.go diff --git a/pkg/strategy/output.go b/pkg/strategy/output.go index 6e2c73ac9..990fbb354 100644 --- a/pkg/strategy/output.go +++ b/pkg/strategy/output.go @@ -7,26 +7,15 @@ import ( "sort" "strings" - "github.com/c9s/bbgo/pkg/bbgo" - "github.com/c9s/bbgo/pkg/util" "github.com/fatih/color" "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" + + "github.com/c9s/bbgo/pkg/bbgo" + "github.com/c9s/bbgo/pkg/types" + "github.com/c9s/bbgo/pkg/util" ) -type JsonStruct struct { - Key string - Json string - Type string - Value interface{} -} - -type JsonArr []JsonStruct - -func (a JsonArr) Len() int { return len(a) } -func (a JsonArr) Less(i, j int) bool { return a[i].Key < a[j].Key } -func (a JsonArr) Swap(i, j int) { a[i], a[j] = a[j], a[i] } - func DefaultStyle() *table.Style { style := table.Style{ Name: "StyleRounded", @@ -86,7 +75,7 @@ func PrintConfig(s interface{}, f io.Writer, style *table.Style, withColor bool, if val.Type().Kind() == util.Pointer { val = val.Elem() } - var values JsonArr + var values types.JsonArr for i := 0; i < val.Type().NumField(); i++ { t := val.Type().Field(i) if !t.IsExported() { @@ -123,7 +112,7 @@ func PrintConfig(s interface{}, f io.Writer, style *table.Style, withColor bool, } redundantSet[name] = struct{}{} value := field.Field(j).Interface() - values = append(values, JsonStruct{Key: fieldName, Json: name, Type: tt.Type.String(), Value: value}) + values = append(values, types.JsonStruct{Key: fieldName, Json: name, Type: tt.Type.String(), Value: value}) } } } @@ -133,7 +122,7 @@ func PrintConfig(s interface{}, f io.Writer, style *table.Style, withColor bool, continue } redundantSet[name] = struct{}{} - values = append(values, JsonStruct{Key: fieldName, Json: name, Type: t.Type.String(), Value: val.Field(i).Interface()}) + values = append(values, types.JsonStruct{Key: fieldName, Json: name, Type: t.Type.String(), Value: val.Field(i).Interface()}) } } sort.Sort(values) diff --git a/pkg/types/json.go b/pkg/types/json.go new file mode 100644 index 000000000..efc54d3ca --- /dev/null +++ b/pkg/types/json.go @@ -0,0 +1,14 @@ +package types + +type JsonStruct struct { + Key string + Json string + Type string + Value interface{} +} + +type JsonArr []JsonStruct + +func (a JsonArr) Len() int { return len(a) } +func (a JsonArr) Less(i, j int) bool { return a[i].Key < a[j].Key } +func (a JsonArr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }