From 957568ed5ce301eb0fd197ff598462e03bed3047 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Thu, 15 Jun 2023 10:13:27 +0800 Subject: [PATCH] doc: format code in doc file --- docs/mathutil_zh-CN.md | 22 ++- docs/netutil.md | 12 +- docs/netutil_zh-CN.md | 12 +- docs/slice.md | 36 ++--- docs/slice_zh-CN.md | 36 ++--- docs/stream.md | 12 +- docs/stream_zh-CN.md | 12 +- docs/structs/field.md | 263 ++++++++++++++++++----------------- docs/structs/field_zh-CN.md | 260 +++++++++++++++++----------------- docs/structs/struct.md | 123 ++++++++-------- docs/structs/struct_zh-CN.md | 123 ++++++++-------- docs/strutil.md | 18 ++- docs/strutil_zh-CN.md | 16 +-- 13 files changed, 472 insertions(+), 473 deletions(-) diff --git a/docs/mathutil_zh-CN.md b/docs/mathutil_zh-CN.md index 72fea04..a3764f9 100644 --- a/docs/mathutil_zh-CN.md +++ b/docs/mathutil_zh-CN.md @@ -789,7 +789,6 @@ func main() { } ``` - ### Cos

计算弧度的余弦值

@@ -832,7 +831,6 @@ func main() { } ``` - ### Sin

计算弧度的正弦值

@@ -897,17 +895,17 @@ import ( func main() { result1 := mathutil.Log(8, 2) - result2 := mathutil.TruncRound(mathutil.Log(5, 2), 2) - result3 := mathutil.TruncRound(mathutil.Log(27, 3), 0) + result2 := mathutil.TruncRound(mathutil.Log(5, 2), 2) + result3 := mathutil.TruncRound(mathutil.Log(27, 3), 0) - fmt.Println(result1) - fmt.Println(result2) - fmt.Println(result3) + fmt.Println(result1) + fmt.Println(result2) + fmt.Println(result3) - // Output: - // 3 - // 2.32 - // 3 + // Output: + // 3 + // 2.32 + // 3 } ``` @@ -942,4 +940,4 @@ func main() { // 3 // 1.1 } -``` \ No newline at end of file +``` diff --git a/docs/netutil.md b/docs/netutil.md index e143778..7e81cda 100644 --- a/docs/netutil.md +++ b/docs/netutil.md @@ -694,15 +694,15 @@ func main() { header := map[string]string{ "Content-Type": "application/x-www-form-urlencoded", } - + postData := url.Values{} - postData.Add("userId", "1") - postData.Add("title", "TestToDo") + postData.Add("userId", "1") + postData.Add("title", "TestToDo") resp, err := netutil.HttpPost(apiUrl, header, nil, postData) - if err != nil { - log.Fatal(err) - } + if err != nil { + log.Fatal(err) + } body, _ := ioutil.ReadAll(resp.Body) fmt.Println(body) diff --git a/docs/netutil_zh-CN.md b/docs/netutil_zh-CN.md index 7b7a869..07a5d0a 100644 --- a/docs/netutil_zh-CN.md +++ b/docs/netutil_zh-CN.md @@ -696,15 +696,15 @@ func main() { header := map[string]string{ "Content-Type": "application/x-www-form-urlencoded", } - + postData := url.Values{} - postData.Add("userId", "1") - postData.Add("title", "TestToDo") + postData.Add("userId", "1") + postData.Add("title", "TestToDo") resp, err := netutil.HttpPost(apiUrl, header, nil, postData) - if err != nil { - log.Fatal(err) - } + if err != nil { + log.Fatal(err) + } body, _ := ioutil.ReadAll(resp.Body) fmt.Println(body) diff --git a/docs/slice.md b/docs/slice.md index fe51433..709c77e 100644 --- a/docs/slice.md +++ b/docs/slice.md @@ -896,18 +896,18 @@ import ( func main() { nums := []int{1, 2, 3, 4, 5} - isEven := func(i, num int) bool { - return num%2 == 0 - } + isEven := func(i, num int) bool { + return num%2 == 0 + } - result, ok := slice.FindBy(nums, isEven) + result, ok := slice.FindBy(nums, isEven) - fmt.Println(result) - fmt.Println(ok) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 2 - // true + // Output: + // 2 + // true } ``` @@ -968,18 +968,18 @@ import ( func main() { nums := []int{1, 2, 3, 4, 5} - isEven := func(i, num int) bool { - return num%2 == 0 - } + isEven := func(i, num int) bool { + return num%2 == 0 + } - result, ok := slice.FindLastBy(nums, isEven) + result, ok := slice.FindLastBy(nums, isEven) - fmt.Println(result) - fmt.Println(ok) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 4 - // true + // Output: + // 4 + // true } ``` diff --git a/docs/slice_zh-CN.md b/docs/slice_zh-CN.md index d87cc67..f66138c 100644 --- a/docs/slice_zh-CN.md +++ b/docs/slice_zh-CN.md @@ -897,18 +897,18 @@ import ( func main() { nums := []int{1, 2, 3, 4, 5} - isEven := func(i, num int) bool { - return num%2 == 0 - } + isEven := func(i, num int) bool { + return num%2 == 0 + } - result, ok := slice.FindBy(nums, isEven) + result, ok := slice.FindBy(nums, isEven) - fmt.Println(result) - fmt.Println(ok) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 2 - // true + // Output: + // 2 + // true } ``` @@ -969,18 +969,18 @@ import ( func main() { nums := []int{1, 2, 3, 4, 5} - isEven := func(i, num int) bool { - return num%2 == 0 - } + isEven := func(i, num int) bool { + return num%2 == 0 + } - result, ok := slice.FindLastBy(nums, isEven) + result, ok := slice.FindLastBy(nums, isEven) - fmt.Println(result) - fmt.Println(ok) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 4 - // true + // Output: + // 4 + // true } ``` diff --git a/docs/stream.md b/docs/stream.md index 2c0c7d5..bb9af2d 100644 --- a/docs/stream.md +++ b/docs/stream.md @@ -689,14 +689,14 @@ import ( func main() { original := stream.FromSlice([]int{3, 2, 1}) - result, ok := original.FindLast() + result, ok := original.FindLast() - fmt.Println(result) - fmt.Println(ok) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 1 - // true + // Output: + // 1 + // true } ``` diff --git a/docs/stream_zh-CN.md b/docs/stream_zh-CN.md index 390162e..4a2168f 100644 --- a/docs/stream_zh-CN.md +++ b/docs/stream_zh-CN.md @@ -689,14 +689,14 @@ import ( func main() { original := stream.FromSlice([]int{3, 2, 1}) - result, ok := original.FindLast() + result, ok := original.FindLast() - fmt.Println(result) - fmt.Println(ok) + fmt.Println(result) + fmt.Println(ok) - // Output: - // 1 - // true + // Output: + // 1 + // true } ``` diff --git a/docs/structs/field.md b/docs/structs/field.md index 02384bd..03d2ceb 100644 --- a/docs/structs/field.md +++ b/docs/structs/field.md @@ -21,6 +21,7 @@ import (
## Index: + - [Tag](#Tag) - [Name](#Name) - [Value](#Value) @@ -57,24 +58,24 @@ func (f *Field) Tag() *Tag package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string `json:"name,omitempty"` - } - p1 := &Parent{"111"} + type Parent struct { + Name string `json:"name,omitempty"` + } + p1 := &Parent{"111"} - s := structs.New(p1) - n, _ := s.Field("Name") - tag := n.Tag() + s := structs.New(p1) + n, _ := s.Field("Name") + tag := n.Tag() - fmt.Println(tag.Name) - - // Output: - // name + fmt.Println(tag.Name) + + // Output: + // name } ``` @@ -94,23 +95,23 @@ func (f *Field) Value() any package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string `json:"name,omitempty"` - } - p1 := &Parent{"111"} + type Parent struct { + Name string `json:"name,omitempty"` + } + p1 := &Parent{"111"} - s := structs.New(p1) - n, _ := s.Field("Name") - - fmt.Println(n.Value()) - - // Output: - // 111 + s := structs.New(p1) + n, _ := s.Field("Name") + + fmt.Println(n.Value()) + + // Output: + // 111 } ``` @@ -130,32 +131,32 @@ func (f *Field) IsEmbedded() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - } - type Child struct { - Parent - Age int - } - c1 := &Child{} - c1.Name = "111" - c1.Age = 11 + type Parent struct { + Name string + } + type Child struct { + Parent + Age int + } + c1 := &Child{} + c1.Name = "111" + c1.Age = 11 - s := structs.New(c1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.IsEmbedded()) - fmt.Println(a.IsEmbedded()) - - // Output: - // true - // false + s := structs.New(c1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.IsEmbedded()) + fmt.Println(a.IsEmbedded()) + + // Output: + // true + // false } ``` @@ -175,26 +176,26 @@ func (f *Field) IsExported() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - age int - } - p1 := &Parent{Name: "11", age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("age") - - fmt.Println(n.IsExported()) - fmt.Println(a.IsExported()) - - // Output: - // true - // false + type Parent struct { + Name string + age int + } + p1 := &Parent{Name: "11", age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("age") + + fmt.Println(n.IsExported()) + fmt.Println(a.IsExported()) + + // Output: + // true + // false } ``` @@ -214,26 +215,26 @@ func (f *Field) IsZero() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - Age int - } - p1 := &Parent{Age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.IsZero()) - fmt.Println(a.IsZero()) - - // Output: - // true - // false + type Parent struct { + Name string + Age int + } + p1 := &Parent{Age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.IsZero()) + fmt.Println(a.IsZero()) + + // Output: + // true + // false } ``` @@ -253,26 +254,26 @@ func (f *Field) Name() string package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - Age int - } - p1 := &Parent{Age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.Name()) - fmt.Println(a.Name()) - - // Output: - // Name - // Age + type Parent struct { + Name string + Age int + } + p1 := &Parent{Age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.Name()) + fmt.Println(a.Name()) + + // Output: + // Name + // Age } ``` @@ -292,26 +293,26 @@ func (f *Field) Kind() reflect.Kind package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - Age int - } - p1 := &Parent{Age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.Kind()) - fmt.Println(a.Kind()) - - // Output: - // string - // int + type Parent struct { + Name string + Age int + } + p1 := &Parent{Age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.Kind()) + fmt.Println(a.Kind()) + + // Output: + // string + // int } ``` @@ -331,23 +332,23 @@ func (f *Field) IsSlice() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - arr []int - } + type Parent struct { + Name string + arr []int + } - p1 := &Parent{arr: []int{1, 2, 3}} - s := structs.New(p1) - a, _ := s.Field("arr") - - fmt.Println(a.IsSlice()) - - // Output: - // true + p1 := &Parent{arr: []int{1, 2, 3}} + s := structs.New(p1) + a, _ := s.Field("arr") + + fmt.Println(a.IsSlice()) + + // Output: + // true } -``` \ No newline at end of file +``` diff --git a/docs/structs/field_zh-CN.md b/docs/structs/field_zh-CN.md index e5d9a0e..03e455c 100644 --- a/docs/structs/field_zh-CN.md +++ b/docs/structs/field_zh-CN.md @@ -57,24 +57,24 @@ func (f *Field) Tag() *Tag package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string `json:"name,omitempty"` - } - p1 := &Parent{"111"} + type Parent struct { + Name string `json:"name,omitempty"` + } + p1 := &Parent{"111"} - s := structs.New(p1) - n, _ := s.Field("Name") - tag := n.Tag() + s := structs.New(p1) + n, _ := s.Field("Name") + tag := n.Tag() - fmt.Println(tag.Name) - - // Output: - // name + fmt.Println(tag.Name) + + // Output: + // name } ``` @@ -94,23 +94,23 @@ func (f *Field) Value() any package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string `json:"name,omitempty"` - } - p1 := &Parent{"111"} + type Parent struct { + Name string `json:"name,omitempty"` + } + p1 := &Parent{"111"} - s := structs.New(p1) - n, _ := s.Field("Name") - - fmt.Println(n.Value()) - - // Output: - // 111 + s := structs.New(p1) + n, _ := s.Field("Name") + + fmt.Println(n.Value()) + + // Output: + // 111 } ``` @@ -130,32 +130,32 @@ func (f *Field) IsEmbedded() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - } - type Child struct { - Parent - Age int - } - c1 := &Child{} - c1.Name = "111" - c1.Age = 11 + type Parent struct { + Name string + } + type Child struct { + Parent + Age int + } + c1 := &Child{} + c1.Name = "111" + c1.Age = 11 - s := structs.New(c1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.IsEmbedded()) - fmt.Println(a.IsEmbedded()) - - // Output: - // true - // false + s := structs.New(c1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.IsEmbedded()) + fmt.Println(a.IsEmbedded()) + + // Output: + // true + // false } ``` @@ -175,26 +175,26 @@ func (f *Field) IsExported() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - age int - } - p1 := &Parent{Name: "11", age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("age") - - fmt.Println(n.IsExported()) - fmt.Println(a.IsExported()) - - // Output: - // true - // false + type Parent struct { + Name string + age int + } + p1 := &Parent{Name: "11", age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("age") + + fmt.Println(n.IsExported()) + fmt.Println(a.IsExported()) + + // Output: + // true + // false } ``` @@ -214,26 +214,26 @@ func (f *Field) IsZero() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - Age int - } - p1 := &Parent{Age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.IsZero()) - fmt.Println(a.IsZero()) - - // Output: - // true - // false + type Parent struct { + Name string + Age int + } + p1 := &Parent{Age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.IsZero()) + fmt.Println(a.IsZero()) + + // Output: + // true + // false } ``` @@ -253,26 +253,26 @@ func (f *Field) Name() string package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - Age int - } - p1 := &Parent{Age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.Name()) - fmt.Println(a.Name()) - - // Output: - // Name - // Age + type Parent struct { + Name string + Age int + } + p1 := &Parent{Age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.Name()) + fmt.Println(a.Name()) + + // Output: + // Name + // Age } ``` @@ -292,26 +292,26 @@ func (f *Field) Kind() reflect.Kind package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - Age int - } - p1 := &Parent{Age: 11} - s := structs.New(p1) - n, _ := s.Field("Name") - a, _ := s.Field("Age") - - fmt.Println(n.Kind()) - fmt.Println(a.Kind()) - - // Output: - // string - // int + type Parent struct { + Name string + Age int + } + p1 := &Parent{Age: 11} + s := structs.New(p1) + n, _ := s.Field("Name") + a, _ := s.Field("Age") + + fmt.Println(n.Kind()) + fmt.Println(a.Kind()) + + // Output: + // string + // int } ``` @@ -331,23 +331,23 @@ func (f *Field) IsSlice() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type Parent struct { - Name string - arr []int - } + type Parent struct { + Name string + arr []int + } - p1 := &Parent{arr: []int{1, 2, 3}} - s := structs.New(p1) - a, _ := s.Field("arr") - - fmt.Println(a.IsSlice()) - - // Output: - // true + p1 := &Parent{arr: []int{1, 2, 3}} + s := structs.New(p1) + a, _ := s.Field("arr") + + fmt.Println(a.IsSlice()) + + // Output: + // true } ``` \ No newline at end of file diff --git a/docs/structs/struct.md b/docs/structs/struct.md index e78afd4..e229f46 100644 --- a/docs/structs/struct.md +++ b/docs/structs/struct.md @@ -21,6 +21,7 @@ import (
## Index: + - [New](#New) - [ToMap](#ToMap) - [Fields](#Fields) @@ -47,16 +48,16 @@ func New(value any, tagName ...string) *Struct package main import ( - "github.com/duke-git/lancet/v2/structs" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) - // to do something + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) + // to do something } ``` @@ -82,29 +83,29 @@ func ToMap(v any) (map[string]any, error) package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - // use constructor function - s1 := structs.New(p1) - m1, _ := s1.ToMap() + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + // use constructor function + s1 := structs.New(p1) + m1, _ := s1.ToMap() - fmt.Println(m1) - - // use static function - m2, _ := structs.ToMap(p1) - - fmt.Println(m2) - - // Output: - // map[name:11] - // map[name:11] + fmt.Println(m1) + + // use static function + m2, _ := structs.ToMap(p1) + + fmt.Println(m2) + + // Output: + // map[name:11] + // map[name:11] } ``` @@ -124,22 +125,22 @@ func (s *Struct) Fields() []*Field package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) - fields := s.Fields() + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) + fields := s.Fields() - fmt.Println(len(fields)) - - // Output: - // 1 + fmt.Println(len(fields)) + + // Output: + // 1 } ``` @@ -159,22 +160,22 @@ func (s *Struct) Field(name string) *Field package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) - f := s.Field("Name") + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) + f := s.Field("Name") - fmt.Println(f.Value()) - - // Output: - // 11 + fmt.Println(f.Value()) + + // Output: + // 11 } ``` @@ -194,20 +195,20 @@ func (s *Struct) IsStruct() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) - fmt.Println(s.IsStruct()) - - // Output: - // true + fmt.Println(s.IsStruct()) + + // Output: + // true } ``` diff --git a/docs/structs/struct_zh-CN.md b/docs/structs/struct_zh-CN.md index 166f12b..e4fc0bf 100644 --- a/docs/structs/struct_zh-CN.md +++ b/docs/structs/struct_zh-CN.md @@ -21,6 +21,7 @@ import (
## 目录: + - [New](#New) - [ToMap](#ToMap) - [Fields](#Fields) @@ -47,16 +48,16 @@ func New(value any, tagName ...string) *Struct package main import ( - "github.com/duke-git/lancet/v2/structs" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) - // to do something + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) + // to do something } ``` @@ -70,7 +71,7 @@ func main() { func (s *Struct) ToMap() (map[string]any, error) ``` -除此之外,提供一个便捷的静态方法ToMap +除此之外,提供一个便捷的静态方法 ToMap ```go func ToMap(v any) (map[string]any, error) @@ -82,28 +83,28 @@ func ToMap(v any) (map[string]any, error) package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s1 := structs.New(p1) - m1, _ := s1.ToMap() + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s1 := structs.New(p1) + m1, _ := s1.ToMap() - fmt.Println(m1) - - // 如果不需要Struct更多的方法,可以直接使用ToMap - m2, _ := structs.ToMap(p1) - - fmt.Println(m2) - - // Output: - // map[name:11] - // map[name:11] + fmt.Println(m1) + + // 如果不需要Struct更多的方法,可以直接使用ToMap + m2, _ := structs.ToMap(p1) + + fmt.Println(m2) + + // Output: + // map[name:11] + // map[name:11] } ``` @@ -123,22 +124,22 @@ func (s *Struct) Fields() []*Field package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) - fields := s.Fields() + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) + fields := s.Fields() - fmt.Println(len(fields)) - - // Output: - // 1 + fmt.Println(len(fields)) + + // Output: + // 1 } ``` @@ -158,22 +159,22 @@ func (s *Struct) Field(name string) *Field package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) - f := s.Field("Name") + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) + f := s.Field("Name") - fmt.Println(f.Value()) - - // Output: - // 11 + fmt.Println(f.Value()) + + // Output: + // 11 } ``` @@ -193,20 +194,20 @@ func (s *Struct) IsStruct() bool package main import ( - "fmt" - "github.com/duke-git/lancet/v2/structs" + "fmt" + "github.com/duke-git/lancet/v2/structs" ) func main() { - type People struct { - Name string `json:"name"` - } - p1 := &People{Name: "11"} - s := structs.New(p1) + type People struct { + Name string `json:"name"` + } + p1 := &People{Name: "11"} + s := structs.New(p1) - fmt.Println(s.IsStruct()) - - // Output: - // true + fmt.Println(s.IsStruct()) + + // Output: + // true } ``` diff --git a/docs/strutil.md b/docs/strutil.md index 4320748..20d5627 100644 --- a/docs/strutil.md +++ b/docs/strutil.md @@ -1322,7 +1322,6 @@ func main() { } ``` - ### ContainsAll

Return true if target string contains all the substrings.

@@ -1392,7 +1391,6 @@ func main() { } ``` - ### RemoveWhiteSpace

Remove whitespace characters from a string. when set repalceAll is true removes all whitespace, false only replaces consecutive whitespace characters with one space.

@@ -1412,16 +1410,16 @@ import ( ) func main() { - str := " hello \r\n \t world" + str := " hello \r\n \t world" - result1 := strutil.RemoveWhiteSpace(str, true) - result2 := strutil.RemoveWhiteSpace(str, false) + result1 := strutil.RemoveWhiteSpace(str, true) + result2 := strutil.RemoveWhiteSpace(str, false) - fmt.Println(result1) - fmt.Println(result2) + fmt.Println(result1) + fmt.Println(result2) - // Output: - // helloworld - // hello world + // Output: + // helloworld + // hello world } ``` diff --git a/docs/strutil_zh-CN.md b/docs/strutil_zh-CN.md index fdf6ae8..309a471 100644 --- a/docs/strutil_zh-CN.md +++ b/docs/strutil_zh-CN.md @@ -1409,16 +1409,16 @@ import ( ) func main() { - str := " hello \r\n \t world" + str := " hello \r\n \t world" - result1 := strutil.RemoveWhiteSpace(str, true) - result2 := strutil.RemoveWhiteSpace(str, false) + result1 := strutil.RemoveWhiteSpace(str, true) + result2 := strutil.RemoveWhiteSpace(str, false) - fmt.Println(result1) - fmt.Println(result2) + fmt.Println(result1) + fmt.Println(result2) - // Output: - // helloworld - // hello world + // Output: + // helloworld + // hello world } ```