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

doc: add docment and example for byte.go

This commit is contained in:
dudaodong
2023-04-07 14:53:48 +08:00
parent 74474cd9ef
commit 4a298876e9
4 changed files with 397 additions and 3 deletions

View File

@@ -59,3 +59,75 @@ func ExamplePrettyToWriter() {
//
// <nil>
}
func ExampleDecimalBytes() {
result1 := DecimalBytes(1000)
result2 := DecimalBytes(1024)
result3 := DecimalBytes(1234567)
result4 := DecimalBytes(1234567, 3)
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
// Output:
// 1KB
// 1.024KB
// 1.2346MB
// 1.235MB
}
func ExampleBinaryBytes() {
result1 := BinaryBytes(1024)
result2 := BinaryBytes(1024 * 1024)
result3 := BinaryBytes(1234567)
result4 := BinaryBytes(1234567, 2)
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
// Output:
// 1KiB
// 1MiB
// 1.1774MiB
// 1.18MiB
}
func ExampleParseDecimalBytes() {
result1, _ := ParseDecimalBytes("12")
result2, _ := ParseDecimalBytes("12k")
result3, _ := ParseDecimalBytes("12 Kb")
result4, _ := ParseDecimalBytes("12.2 kb")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
// Output:
// 12
// 12000
// 12000
// 12200
}
func ExampleParseBinaryBytes() {
result1, _ := ParseBinaryBytes("12")
result2, _ := ParseBinaryBytes("12ki")
result3, _ := ParseBinaryBytes("12 KiB")
result4, _ := ParseBinaryBytes("12.2 kib")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
// Output:
// 12
// 12288
// 12288
// 12492
}