1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 08:12:26 +08:00

doc: format code in doc file

This commit is contained in:
dudaodong
2023-06-15 10:13:27 +08:00
parent fffabd0ffa
commit 957568ed5c
13 changed files with 472 additions and 473 deletions

View File

@@ -21,6 +21,7 @@ import (
<div STYLE="page-break-after: always;"></div>
## 目录:
- [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)
```
<b>除此之外提供一个便捷的静态方法ToMap</b>
<b>除此之外,提供一个便捷的静态方法 ToMap</b>
```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
}
```