1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-17 19:22:28 +08:00

feat: add Pretty and PrettyToWriter

This commit is contained in:
dudaodong
2023-04-06 16:30:38 +08:00
parent 18f01ffd75
commit f23f18457e
5 changed files with 286 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
package formatter
import "fmt"
import (
"bytes"
"fmt"
)
func ExampleComma() {
result1 := Comma("123", "")
@@ -16,3 +19,43 @@ func ExampleComma() {
// $12,345
// ¥1,234,567
}
func ExamplePretty() {
result1, _ := Pretty([]string{"a", "b", "c"})
result2, _ := Pretty(map[string]int{"a": 1})
fmt.Println(result1)
fmt.Println(result2)
// Output:
// [
// "a",
// "b",
// "c"
// ]
// {
// "a": 1
// }
}
func ExamplePrettyToWriter() {
type User struct {
Name string `json:"name"`
Aage uint `json:"age"`
}
user := User{Name: "King", Aage: 10000}
buf := &bytes.Buffer{}
err := PrettyToWriter(user, buf)
fmt.Println(buf)
fmt.Println(err)
// Output:
// {
// "name": "King",
// "age": 10000
// }
//
// <nil>
}