package bytesize_test import ( "encoding/json" "fmt" "gitoa.ru/go-4devs/bytesize" ) func ExampleParse() { size, err := bytesize.Parse("100kB") fmt.Printf("100kB:%[1]T(%[1]d),%[2]v\n", size, err) size, err = bytesize.Parse("100PB") fmt.Printf("100PB:%[1]T(%[1]d),%[2]v\n", size, err) size, err = bytesize.Parse("100KiB") fmt.Printf("100PB:%[1]T(%[1]d),%[2]v\n", size, err) size, err = bytesize.Parse("100MiB") fmt.Printf("100PB:%[1]T(%[1]d),%[2]v\n", size, err) size, err = bytesize.Parse("100B") fmt.Printf("100PB:%[1]T(%[1]d),%[2]v\n", size, err) // Output: // 100kB:bytesize.Size(100000), // 100PB:bytesize.Size(100000000000000000), // 100PB:bytesize.Size(102400), // 100PB:bytesize.Size(104857600), // 100PB:bytesize.Size(100), } func ExampleSize_String() { fmt.Printf("%[1]T(%[1]d) = %[1]s\n", bytesize.Size(100000)) fmt.Printf("%[1]T(%[1]d) = %[1]s\n", bytesize.Size(100000000000000000)) fmt.Printf("%[1]T(%[1]d) = %[1]s\n", bytesize.Size(102400)) fmt.Printf("%[1]T(%[1]d) = %[1]s\n", bytesize.Size(104857600)) fmt.Printf("%[1]T(%[1]d) = %[1]s\n", bytesize.Size(100)) // Output: // bytesize.Size(100000) = 100kB // bytesize.Size(100000000000000000) = 100PB // bytesize.Size(102400) = 102.4kB // bytesize.Size(104857600) = 104.8576MB // bytesize.Size(100) = 100B } func ExampleSize_jsonMarshal() { size := bytesize.Size(100000) data, _ := json.Marshal(size) fmt.Printf("%[1]T(%[1]d) = %[2]s\n", size, data) size = bytesize.Size(100000000000000000) data, _ = json.Marshal(size) fmt.Printf("%[1]T(%[1]d) = %[2]s\n", size, data) size = bytesize.Size(102400) data, _ = json.Marshal(size) fmt.Printf("%[1]T(%[1]d) = %[2]s\n", size, data) size = bytesize.Size(104857600) data, _ = json.Marshal(size) fmt.Printf("%[1]T(%[1]d) = %[2]s\n", size, data) size = bytesize.Size(100) data, _ = json.Marshal(size) fmt.Printf("%[1]T(%[1]d) = %[2]s\n", size, data) // Output: // bytesize.Size(100000) = "100kB" // bytesize.Size(100000000000000000) = "100PB" // bytesize.Size(102400) = "102.4kB" // bytesize.Size(104857600) = "104.8576MB" // bytesize.Size(100) = "100B" }