mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-15 18:22:27 +08:00
doc: format code in doc file
This commit is contained in:
@@ -789,7 +789,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="Cos">Cos</span>
|
### <span id="Cos">Cos</span>
|
||||||
|
|
||||||
<p>计算弧度的余弦值</p>
|
<p>计算弧度的余弦值</p>
|
||||||
@@ -832,7 +831,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="Sin">Sin</span>
|
### <span id="Sin">Sin</span>
|
||||||
|
|
||||||
<p>计算弧度的正弦值</p>
|
<p>计算弧度的正弦值</p>
|
||||||
@@ -897,17 +895,17 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := mathutil.Log(8, 2)
|
result1 := mathutil.Log(8, 2)
|
||||||
result2 := mathutil.TruncRound(mathutil.Log(5, 2), 2)
|
result2 := mathutil.TruncRound(mathutil.Log(5, 2), 2)
|
||||||
result3 := mathutil.TruncRound(mathutil.Log(27, 3), 0)
|
result3 := mathutil.TruncRound(mathutil.Log(27, 3), 0)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 3
|
// 3
|
||||||
// 2.32
|
// 2.32
|
||||||
// 3
|
// 3
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -696,13 +696,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postData := url.Values{}
|
postData := url.Values{}
|
||||||
postData.Add("userId", "1")
|
postData.Add("userId", "1")
|
||||||
postData.Add("title", "TestToDo")
|
postData.Add("title", "TestToDo")
|
||||||
|
|
||||||
resp, err := netutil.HttpPost(apiUrl, header, nil, postData)
|
resp, err := netutil.HttpPost(apiUrl, header, nil, postData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
fmt.Println(body)
|
fmt.Println(body)
|
||||||
|
|||||||
@@ -698,13 +698,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postData := url.Values{}
|
postData := url.Values{}
|
||||||
postData.Add("userId", "1")
|
postData.Add("userId", "1")
|
||||||
postData.Add("title", "TestToDo")
|
postData.Add("title", "TestToDo")
|
||||||
|
|
||||||
resp, err := netutil.HttpPost(apiUrl, header, nil, postData)
|
resp, err := netutil.HttpPost(apiUrl, header, nil, postData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
fmt.Println(body)
|
fmt.Println(body)
|
||||||
|
|||||||
@@ -896,18 +896,18 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
nums := []int{1, 2, 3, 4, 5}
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
isEven := func(i, num int) bool {
|
isEven := func(i, num int) bool {
|
||||||
return num%2 == 0
|
return num%2 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
result, ok := slice.FindBy(nums, isEven)
|
result, ok := slice.FindBy(nums, isEven)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
fmt.Println(ok)
|
fmt.Println(ok)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 2
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -968,18 +968,18 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
nums := []int{1, 2, 3, 4, 5}
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
isEven := func(i, num int) bool {
|
isEven := func(i, num int) bool {
|
||||||
return num%2 == 0
|
return num%2 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
result, ok := slice.FindLastBy(nums, isEven)
|
result, ok := slice.FindLastBy(nums, isEven)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
fmt.Println(ok)
|
fmt.Println(ok)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 4
|
// 4
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -897,18 +897,18 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
nums := []int{1, 2, 3, 4, 5}
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
isEven := func(i, num int) bool {
|
isEven := func(i, num int) bool {
|
||||||
return num%2 == 0
|
return num%2 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
result, ok := slice.FindBy(nums, isEven)
|
result, ok := slice.FindBy(nums, isEven)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
fmt.Println(ok)
|
fmt.Println(ok)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 2
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -969,18 +969,18 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
nums := []int{1, 2, 3, 4, 5}
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
isEven := func(i, num int) bool {
|
isEven := func(i, num int) bool {
|
||||||
return num%2 == 0
|
return num%2 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
result, ok := slice.FindLastBy(nums, isEven)
|
result, ok := slice.FindLastBy(nums, isEven)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
fmt.Println(ok)
|
fmt.Println(ok)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 4
|
// 4
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -689,14 +689,14 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
original := stream.FromSlice([]int{3, 2, 1})
|
original := stream.FromSlice([]int{3, 2, 1})
|
||||||
|
|
||||||
result, ok := original.FindLast()
|
result, ok := original.FindLast()
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
fmt.Println(ok)
|
fmt.Println(ok)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1
|
// 1
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -689,14 +689,14 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
original := stream.FromSlice([]int{3, 2, 1})
|
original := stream.FromSlice([]int{3, 2, 1})
|
||||||
|
|
||||||
result, ok := original.FindLast()
|
result, ok := original.FindLast()
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
fmt.Println(ok)
|
fmt.Println(ok)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1
|
// 1
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Index:
|
## Index:
|
||||||
|
|
||||||
- [Tag](#Tag)
|
- [Tag](#Tag)
|
||||||
- [Name](#Name)
|
- [Name](#Name)
|
||||||
- [Value](#Value)
|
- [Value](#Value)
|
||||||
@@ -57,24 +58,24 @@ func (f *Field) Tag() *Tag
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
p1 := &Parent{"111"}
|
p1 := &Parent{"111"}
|
||||||
|
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
tag := n.Tag()
|
tag := n.Tag()
|
||||||
|
|
||||||
fmt.Println(tag.Name)
|
fmt.Println(tag.Name)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// name
|
// name
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -94,23 +95,23 @@ func (f *Field) Value() any
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
p1 := &Parent{"111"}
|
p1 := &Parent{"111"}
|
||||||
|
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
|
|
||||||
fmt.Println(n.Value())
|
fmt.Println(n.Value())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 111
|
// 111
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -130,32 +131,32 @@ func (f *Field) IsEmbedded() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
type Child struct {
|
type Child struct {
|
||||||
Parent
|
Parent
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
c1 := &Child{}
|
c1 := &Child{}
|
||||||
c1.Name = "111"
|
c1.Name = "111"
|
||||||
c1.Age = 11
|
c1.Age = 11
|
||||||
|
|
||||||
s := structs.New(c1)
|
s := structs.New(c1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.IsEmbedded())
|
fmt.Println(n.IsEmbedded())
|
||||||
fmt.Println(a.IsEmbedded())
|
fmt.Println(a.IsEmbedded())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -175,26 +176,26 @@ func (f *Field) IsExported() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
age int
|
age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Name: "11", age: 11}
|
p1 := &Parent{Name: "11", age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("age")
|
a, _ := s.Field("age")
|
||||||
|
|
||||||
fmt.Println(n.IsExported())
|
fmt.Println(n.IsExported())
|
||||||
fmt.Println(a.IsExported())
|
fmt.Println(a.IsExported())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -214,26 +215,26 @@ func (f *Field) IsZero() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Age: 11}
|
p1 := &Parent{Age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.IsZero())
|
fmt.Println(n.IsZero())
|
||||||
fmt.Println(a.IsZero())
|
fmt.Println(a.IsZero())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -253,26 +254,26 @@ func (f *Field) Name() string
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Age: 11}
|
p1 := &Parent{Age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.Name())
|
fmt.Println(n.Name())
|
||||||
fmt.Println(a.Name())
|
fmt.Println(a.Name())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// Name
|
// Name
|
||||||
// Age
|
// Age
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -292,26 +293,26 @@ func (f *Field) Kind() reflect.Kind
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Age: 11}
|
p1 := &Parent{Age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.Kind())
|
fmt.Println(n.Kind())
|
||||||
fmt.Println(a.Kind())
|
fmt.Println(a.Kind())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// string
|
// string
|
||||||
// int
|
// int
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -331,23 +332,23 @@ func (f *Field) IsSlice() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
arr []int
|
arr []int
|
||||||
}
|
}
|
||||||
|
|
||||||
p1 := &Parent{arr: []int{1, 2, 3}}
|
p1 := &Parent{arr: []int{1, 2, 3}}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
a, _ := s.Field("arr")
|
a, _ := s.Field("arr")
|
||||||
|
|
||||||
fmt.Println(a.IsSlice())
|
fmt.Println(a.IsSlice())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -57,24 +57,24 @@ func (f *Field) Tag() *Tag
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
p1 := &Parent{"111"}
|
p1 := &Parent{"111"}
|
||||||
|
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
tag := n.Tag()
|
tag := n.Tag()
|
||||||
|
|
||||||
fmt.Println(tag.Name)
|
fmt.Println(tag.Name)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// name
|
// name
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -94,23 +94,23 @@ func (f *Field) Value() any
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
p1 := &Parent{"111"}
|
p1 := &Parent{"111"}
|
||||||
|
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
|
|
||||||
fmt.Println(n.Value())
|
fmt.Println(n.Value())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 111
|
// 111
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -130,32 +130,32 @@ func (f *Field) IsEmbedded() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
type Child struct {
|
type Child struct {
|
||||||
Parent
|
Parent
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
c1 := &Child{}
|
c1 := &Child{}
|
||||||
c1.Name = "111"
|
c1.Name = "111"
|
||||||
c1.Age = 11
|
c1.Age = 11
|
||||||
|
|
||||||
s := structs.New(c1)
|
s := structs.New(c1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.IsEmbedded())
|
fmt.Println(n.IsEmbedded())
|
||||||
fmt.Println(a.IsEmbedded())
|
fmt.Println(a.IsEmbedded())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -175,26 +175,26 @@ func (f *Field) IsExported() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
age int
|
age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Name: "11", age: 11}
|
p1 := &Parent{Name: "11", age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("age")
|
a, _ := s.Field("age")
|
||||||
|
|
||||||
fmt.Println(n.IsExported())
|
fmt.Println(n.IsExported())
|
||||||
fmt.Println(a.IsExported())
|
fmt.Println(a.IsExported())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -214,26 +214,26 @@ func (f *Field) IsZero() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Age: 11}
|
p1 := &Parent{Age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.IsZero())
|
fmt.Println(n.IsZero())
|
||||||
fmt.Println(a.IsZero())
|
fmt.Println(a.IsZero())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -253,26 +253,26 @@ func (f *Field) Name() string
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Age: 11}
|
p1 := &Parent{Age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.Name())
|
fmt.Println(n.Name())
|
||||||
fmt.Println(a.Name())
|
fmt.Println(a.Name())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// Name
|
// Name
|
||||||
// Age
|
// Age
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -292,26 +292,26 @@ func (f *Field) Kind() reflect.Kind
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
}
|
}
|
||||||
p1 := &Parent{Age: 11}
|
p1 := &Parent{Age: 11}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
n, _ := s.Field("Name")
|
n, _ := s.Field("Name")
|
||||||
a, _ := s.Field("Age")
|
a, _ := s.Field("Age")
|
||||||
|
|
||||||
fmt.Println(n.Kind())
|
fmt.Println(n.Kind())
|
||||||
fmt.Println(a.Kind())
|
fmt.Println(a.Kind())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// string
|
// string
|
||||||
// int
|
// int
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -331,23 +331,23 @@ func (f *Field) IsSlice() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
Name string
|
Name string
|
||||||
arr []int
|
arr []int
|
||||||
}
|
}
|
||||||
|
|
||||||
p1 := &Parent{arr: []int{1, 2, 3}}
|
p1 := &Parent{arr: []int{1, 2, 3}}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
a, _ := s.Field("arr")
|
a, _ := s.Field("arr")
|
||||||
|
|
||||||
fmt.Println(a.IsSlice())
|
fmt.Println(a.IsSlice())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Index:
|
## Index:
|
||||||
|
|
||||||
- [New](#New)
|
- [New](#New)
|
||||||
- [ToMap](#ToMap)
|
- [ToMap](#ToMap)
|
||||||
- [Fields](#Fields)
|
- [Fields](#Fields)
|
||||||
@@ -47,16 +48,16 @@ func New(value any, tagName ...string) *Struct
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
// to do something
|
// to do something
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -82,29 +83,29 @@ func ToMap(v any) (map[string]any, error)
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
// use constructor function
|
// use constructor function
|
||||||
s1 := structs.New(p1)
|
s1 := structs.New(p1)
|
||||||
m1, _ := s1.ToMap()
|
m1, _ := s1.ToMap()
|
||||||
|
|
||||||
fmt.Println(m1)
|
fmt.Println(m1)
|
||||||
|
|
||||||
// use static function
|
// use static function
|
||||||
m2, _ := structs.ToMap(p1)
|
m2, _ := structs.ToMap(p1)
|
||||||
|
|
||||||
fmt.Println(m2)
|
fmt.Println(m2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// map[name:11]
|
// map[name:11]
|
||||||
// map[name:11]
|
// map[name:11]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -124,22 +125,22 @@ func (s *Struct) Fields() []*Field
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
fields := s.Fields()
|
fields := s.Fields()
|
||||||
|
|
||||||
fmt.Println(len(fields))
|
fmt.Println(len(fields))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1
|
// 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -159,22 +160,22 @@ func (s *Struct) Field(name string) *Field
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
f := s.Field("Name")
|
f := s.Field("Name")
|
||||||
|
|
||||||
fmt.Println(f.Value())
|
fmt.Println(f.Value())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 11
|
// 11
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -194,20 +195,20 @@ func (s *Struct) IsStruct() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
|
|
||||||
fmt.Println(s.IsStruct())
|
fmt.Println(s.IsStruct())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 目录:
|
## 目录:
|
||||||
|
|
||||||
- [New](#New)
|
- [New](#New)
|
||||||
- [ToMap](#ToMap)
|
- [ToMap](#ToMap)
|
||||||
- [Fields](#Fields)
|
- [Fields](#Fields)
|
||||||
@@ -47,16 +48,16 @@ func New(value any, tagName ...string) *Struct
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
// to do something
|
// to do something
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ func main() {
|
|||||||
func (s *Struct) ToMap() (map[string]any, error)
|
func (s *Struct) ToMap() (map[string]any, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>除此之外,提供一个便捷的静态方法ToMap</b>
|
<b>除此之外,提供一个便捷的静态方法 ToMap</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func ToMap(v any) (map[string]any, error)
|
func ToMap(v any) (map[string]any, error)
|
||||||
@@ -82,28 +83,28 @@ func ToMap(v any) (map[string]any, error)
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s1 := structs.New(p1)
|
s1 := structs.New(p1)
|
||||||
m1, _ := s1.ToMap()
|
m1, _ := s1.ToMap()
|
||||||
|
|
||||||
fmt.Println(m1)
|
fmt.Println(m1)
|
||||||
|
|
||||||
// 如果不需要Struct更多的方法,可以直接使用ToMap
|
// 如果不需要Struct更多的方法,可以直接使用ToMap
|
||||||
m2, _ := structs.ToMap(p1)
|
m2, _ := structs.ToMap(p1)
|
||||||
|
|
||||||
fmt.Println(m2)
|
fmt.Println(m2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// map[name:11]
|
// map[name:11]
|
||||||
// map[name:11]
|
// map[name:11]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -123,22 +124,22 @@ func (s *Struct) Fields() []*Field
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
fields := s.Fields()
|
fields := s.Fields()
|
||||||
|
|
||||||
fmt.Println(len(fields))
|
fmt.Println(len(fields))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1
|
// 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -158,22 +159,22 @@ func (s *Struct) Field(name string) *Field
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
f := s.Field("Name")
|
f := s.Field("Name")
|
||||||
|
|
||||||
fmt.Println(f.Value())
|
fmt.Println(f.Value())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 11
|
// 11
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -193,20 +194,20 @@ func (s *Struct) IsStruct() bool
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type People struct {
|
type People struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
p1 := &People{Name: "11"}
|
p1 := &People{Name: "11"}
|
||||||
s := structs.New(p1)
|
s := structs.New(p1)
|
||||||
|
|
||||||
fmt.Println(s.IsStruct())
|
fmt.Println(s.IsStruct())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1322,7 +1322,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="ContainsAll">ContainsAll</span>
|
### <span id="ContainsAll">ContainsAll</span>
|
||||||
|
|
||||||
<p>Return true if target string contains all the substrings.</p>
|
<p>Return true if target string contains all the substrings.</p>
|
||||||
@@ -1392,7 +1391,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="RemoveWhiteSpace">RemoveWhiteSpace</span>
|
### <span id="RemoveWhiteSpace">RemoveWhiteSpace</span>
|
||||||
|
|
||||||
<p>Remove whitespace characters from a string. when set repalceAll is true removes all whitespace, false only replaces consecutive whitespace characters with one space.</p>
|
<p>Remove whitespace characters from a string. when set repalceAll is true removes all whitespace, false only replaces consecutive whitespace characters with one space.</p>
|
||||||
@@ -1412,16 +1410,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
str := " hello \r\n \t world"
|
str := " hello \r\n \t world"
|
||||||
|
|
||||||
result1 := strutil.RemoveWhiteSpace(str, true)
|
result1 := strutil.RemoveWhiteSpace(str, true)
|
||||||
result2 := strutil.RemoveWhiteSpace(str, false)
|
result2 := strutil.RemoveWhiteSpace(str, false)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// helloworld
|
// helloworld
|
||||||
// hello world
|
// hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1409,16 +1409,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
str := " hello \r\n \t world"
|
str := " hello \r\n \t world"
|
||||||
|
|
||||||
result1 := strutil.RemoveWhiteSpace(str, true)
|
result1 := strutil.RemoveWhiteSpace(str, true)
|
||||||
result2 := strutil.RemoveWhiteSpace(str, false)
|
result2 := strutil.RemoveWhiteSpace(str, false)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// helloworld
|
// helloworld
|
||||||
// hello world
|
// hello world
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user