-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathexample_test.go
More file actions
53 lines (41 loc) · 869 Bytes
/
example_test.go
File metadata and controls
53 lines (41 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package bytesize_test
import (
"fmt"
"github.com/inhies/go-bytesize"
)
func ExampleNew() {
b := bytesize.New(1024)
fmt.Printf("%s", b)
// Output:
// 1.00KB
}
// Demonstrates using different output formatting and units.
func ExampleByteSize_Format() {
b := 1 * bytesize.TB // Create a new 1 terabyte ByteSize.
fmt.Printf("%s\n", b)
fmt.Printf("%s\n", b.Format("%.8f ", "petabyte", true))
// Output:
// 1.00TB
// 0.00097656 petabytes
}
func ExampleNew_math() {
b1 := bytesize.New(1024)
b2 := bytesize.New(4096)
sum := b1 + b2
fmt.Printf("%s", sum)
// Output:
// 5.00KB
}
func ExampleParse() {
b, _ := bytesize.Parse("1024 GB")
fmt.Printf("%s\n", b)
b, _ = bytesize.Parse("3 petabytes")
fmt.Printf("%s\n", b)
bytesize.LongUnits = true
bytesize.Format = "%.0f "
fmt.Printf("%s\n", b)
// Output:
// 1.00TB
// 3.00PB
// 3 petabytes
}