diff --git a/show/base.go b/show/base.go index 9364c72..748e78c 100644 --- a/show/base.go +++ b/show/base.go @@ -94,7 +94,7 @@ const ( type Items struct { List []*Item // raw data - data interface{} + data any // inner context itemType string rowNumber int @@ -102,7 +102,7 @@ type Items struct { } // NewItems create a Items for data. -func NewItems(data interface{}) *Items { +func NewItems(data any) *Items { items := &Items{ data: data, itemType: ItemMap, @@ -194,11 +194,11 @@ type Item struct { index int // valLen int keyLen int - // rawVal interface{} + // rawVal any rftVal reflect.Value } -func newItem(key interface{}, rv reflect.Value, index int) *Item { +func newItem(key any, rv reflect.Value, index int) *Item { item := &Item{ Key: strutil.QuietString(key), // Val: fmt.Sprint(value), diff --git a/show/list.go b/show/list.go index 20fac10..4208307 100644 --- a/show/list.go +++ b/show/list.go @@ -44,7 +44,7 @@ type List struct { // Title list title name title string // list data. allow type: struct, slice, array, map - data interface{} + data any // formatted data buffer buffer *bytes.Buffer } @@ -59,7 +59,7 @@ func (l *List) SetBuffer(buffer *bytes.Buffer) { // data allow type: // // struct, slice, array, map -func NewList(title string, data interface{}, fns ...ListOpFunc) *List { +func NewList(title string, data any, fns ...ListOpFunc) *List { l := &List{ title: title, data: data, @@ -206,7 +206,7 @@ type Lists struct { } // NewLists create lists -func NewLists(listMap map[string]interface{}, fns ...ListOpFunc) *Lists { +func NewLists(listMap map[string]any, fns ...ListOpFunc) *Lists { ls := &Lists{ Base: Base{output: Output}, Opts: &ListOption{ diff --git a/show/show.go b/show/show.go index 11413fe..76269e7 100644 --- a/show/show.go +++ b/show/show.go @@ -21,21 +21,21 @@ func SetOutput(out io.Writer) { Output = out } func ResetOutput() { Output = os.Stdout } // Error tips message print -func Error(format string, v ...interface{}) int { +func Error(format string, v ...any) int { prefix := color.Red.Sprint("ERROR: ") _, _ = fmt.Fprintf(Output, prefix+format+"\n", v...) return ERR } // Success tips message print -func Success(format string, v ...interface{}) int { +func Success(format string, v ...any) int { prefix := color.Green.Sprint("SUCCESS: ") _, _ = fmt.Fprintf(Output, prefix+format+"\n", v...) return OK } // JSON print pretty JSON data -func JSON(v interface{}, prefixAndIndent ...string) int { +func JSON(v any, prefixAndIndent ...string) int { prefix := "" indent := " " @@ -61,7 +61,7 @@ func JSON(v interface{}, prefixAndIndent ...string) int { // Usage: // // show.AList("some info", map[string]string{"name": "tom"}) -func AList(title string, data interface{}, fns ...ListOpFunc) { +func AList(title string, data any, fns ...ListOpFunc) { NewList(title, data).WithOptionFns(fns).Println() } @@ -73,7 +73,7 @@ func AList(title string, data interface{}, fns ...ListOpFunc) { // show.MList(data, func(opts *ListOption) { // opts.LeftIndent = " " // }) -func MList(listMap map[string]interface{}, fns ...ListOpFunc) { +func MList(listMap map[string]any, fns ...ListOpFunc) { NewLists(listMap).WithOptionFns(fns).Println() } diff --git a/show/show_test.go b/show/show_test.go index e4c117a..c180a81 100644 --- a/show/show_test.go +++ b/show/show_test.go @@ -28,7 +28,7 @@ func TestList(t *testing.T) { } func TestList_mlevel(t *testing.T) { - d := map[string]interface{}{ + d := map[string]any{ "key0": "list item 0", "key2": []string{"abc", "def"}, "key4": map[string]int{"abc": 23, "def": 45}, @@ -46,7 +46,7 @@ func TestList_mlevel(t *testing.T) { } func TestLists(t *testing.T) { - ls := show.NewLists(map[string]interface{}{ + ls := show.NewLists(map[string]any{ "test list": []string{ "list item 0", "list item 1", diff --git a/show/table.go b/show/table.go index 27edd60..e8017bc 100644 --- a/show/table.go +++ b/show/table.go @@ -17,7 +17,7 @@ type Table struct { // Cols the table head col data Cols []string // Rows table data rows - Rows []interface{} + Rows []any // options ... // HasBorder show border line HasBorder bool