Skip to content

Commit

Permalink
chore: show - replace the interface{} to go1.18 any
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 4, 2022
1 parent 8dfcc56 commit ff70ef3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions show/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ const (
type Items struct {
List []*Item
// raw data
data interface{}
data any
// inner context
itemType string
rowNumber int
keyMaxWidth int
}

// NewItems create a Items for data.
func NewItems(data interface{}) *Items {
func NewItems(data any) *Items {
items := &Items{
data: data,
itemType: ItemMap,
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions show/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions show/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := " "

Expand All @@ -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()
}

Expand All @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions show/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion show/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff70ef3

Please sign in to comment.