Skip to content

Commit

Permalink
doc: fix doc text error
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Mar 6, 2024
1 parent a6eaaef commit aa74400
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 103 deletions.
174 changes: 71 additions & 103 deletions docs/en/api/packages/convertor.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ func main() {
}
```


### <span id="EncodeByte">EncodeByte</span>

<p>Encode data to byte slice.</p>
Expand Down Expand Up @@ -610,7 +611,7 @@ func main() {
func DecodeByte(data []byte, target any) error
```

<b>Example:<span style="float:right;display:inline-block;"></b>
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>

```go
package main
Expand All @@ -636,69 +637,6 @@ func main() {
}
```

### <span id="DeepClone">DeepClone</span>

<p>Creates a deep copy of passed item, can't clone unexported field of struct.</p>

<b>Signature:</b>

```go
func DeepClone[T any](src T) T
```

<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/j4DP5dquxnk)</span></b>

```go
package main

import (
"fmt"
"github.com/duke-git/lancet/v2/convertor"
)

func main() {
type Struct struct {
Str string
Int int
Float float64
Bool bool
Nil interface{}
unexported string
}

cases := []interface{}{
true,
1,
0.1,
map[string]int{
"a": 1,
"b": 2,
},
&Struct{
Str: "test",
Int: 1,
Float: 0.1,
Bool: true,
Nil: nil,
// unexported: "can't be cloned",
},
}

for _, item := range cases {
cloned := convertor.DeepClone(item)

isPointerEqual := &cloned == &item
fmt.Println(cloned, isPointerEqual)
}

// Output:
// true false
// 1 false
// 0.1 false
// map[a:1 b:2] false
// &{test 1 0.1 true <nil> } false
}
```

### <span id="CopyProperties">CopyProperties</span>

Expand Down Expand Up @@ -779,41 +717,6 @@ func main() {
}
```

### <span id="ToInterface">ToInterface</span>

<p>Converts reflect value to its interface type.</p>

<b>Signature:</b>

```go
func ToInterface(v reflect.Value) (value interface{}, ok bool)
```

<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/syqw0-WG7Xd)</span></b>

```go
package main

import (
"fmt"
"github.com/duke-git/lancet/v2/convertor"
)

func main() {
val := reflect.ValueOf("abc")
iVal, ok := convertor.ToInterface(val)

fmt.Printf("%T\n", iVal)
fmt.Printf("%v\n", iVal)
fmt.Println(ok)

// Output:
// string
// abc
// true
}
```

### <span id="Utf8ToGbk">Utf8ToGbk</span>

<p>Converts utf8 encoding data to GBK encoding data.</p>
Expand Down Expand Up @@ -883,7 +786,7 @@ func main() {

### <span id="ToStdBase64">ToStdBase64</span>

<p>Convert a value to a string encoded in standard Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON-formatted string.</p>
<p>Convert a value to a string encoded in standard Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON formatted string.</p>

<b>Signature:</b>

Expand Down Expand Up @@ -953,9 +856,11 @@ func main() {

```



### <span id="ToUrlBase64">ToUrlBase64</span>

<p>Convert a value to a string encoded in url Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON-formatted string.</p>
<p>Convert a value to a string encoded in url Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON formatted string.</p>

<b>Signature:</b>

Expand Down Expand Up @@ -1024,7 +929,7 @@ func main() {

### <span id="ToRawStdBase64">ToRawStdBase64</span>

<p>Convert a value to a string encoded in raw standard Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON-formatted string.</p>
<p>Convert a value to a string encoded in raw standard Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON formatted string.</p>

<b>Signature:</b>

Expand Down Expand Up @@ -1088,7 +993,7 @@ func main() {

### <span id="ToRawUrlBase64">ToRawUrlBase64</span>

<p> Convert a value to a string encoded in raw url Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON-formatted string.</p>
<p> Convert a value to a string encoded in raw url Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON formatted string.</p>

<b>Signature:</b>

Expand Down Expand Up @@ -1148,4 +1053,67 @@ func main() {
// dHJ1ZQ
// ZXJy
}
```

### <span id="DeepClone">DeepClone</span>

<p>Creates a deep copy of passed item, can't clone unexported field of struct.</p>

<b>Signature:</b>

```go
func DeepClone[T any](src T) T
```

<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/j4DP5dquxnk)</span></b>

```go
package main

import (
"fmt"
"github.com/duke-git/lancet/v2/convertor"
)

func main() {
type Struct struct {
Str string
Int int
Float float64
Bool bool
Nil interface{}
unexported string
}

cases := []interface{}{
true,
1,
0.1,
map[string]int{
"a": 1,
"b": 2,
},
&Struct{
Str: "test",
Int: 1,
Float: 0.1,
Bool: true,
Nil: nil,
},
}

for _, item := range cases {
cloned := convertor.DeepClone(item)

isPointerEqual := &cloned == &item
fmt.Println(cloned, isPointerEqual)
}

// Output:
// true false
// 1 false
// 0.1 false
// map[a:1 b:2] false
// &{test 1 0.1 true <nil> } false
}
```
35 changes: 35 additions & 0 deletions docs/en/api/packages/datastructure/hashmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,38 @@ func main() {
```



### <span id="ToInterface">ToInterface</span>

<p>Converts reflect value to its interface type.</p>

<b>Signature:</b>

```go
func ToInterface(v reflect.Value) (value interface{}, ok bool)
```

<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/syqw0-WG7Xd)</span></b>

```go
package main

import (
"fmt"
"github.com/duke-git/lancet/v2/convertor"
)

func main() {
val := reflect.ValueOf("abc")
iVal, ok := convertor.ToInterface(val)

fmt.Printf("%T\n", iVal)
fmt.Printf("%v\n", iVal)
fmt.Println(ok)

// Output:
// string
// abc
// true
}
```
1 change: 1 addition & 0 deletions docs/en/api/packages/slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import (
- [KeyBy](#KeyBy)
- [Join](#Join)
- [Partition](#Partition)
- [SetToDefaultIf](#SetToDefaultIf)

<div STYLE="page-break-after: always;"></div>

Expand Down

0 comments on commit aa74400

Please sign in to comment.