Categorygithub.com/daegalus/go-dataunits
repositorypackage
0.0.0-20240409174808-f57cf1e696a3
Repository: https://github.com/daegalus/go-dataunits.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Go Data Units

License Go Report Card GoDoc

This is a library that provides utility functions for working with various data units in Go. Primarily for Storage sizes and Memory sizes.

Features

  • Conversion between different data units (bytes, kilobytes, megabytes, etc.)
  • Formatting data sizes for display
  • Parsing data sizes from strings

Usage

To use the library, use the following command:

go get github.com/daegalus/go-dataunits

then import it

import (
  "github.com/daegalus/go-dataunits"
)

Example

package main

import (
 "fmt"
 "github.com/daegalus/go-dataunits"
)

func main() {
 ds, err := dataunits.ParseSize[storage.StorageUnit]("1.5GiB")
 if err != nil {
  fmt.Println("Error parsing size:", err)
  return
 }

 fmt.Println("Parsed size:", ds.Size) // 1.5
 fmt.Println("Parsed size in bytes:", ds.Bytes) // 1610612736.0
 fmt.Println("Parsed Unit in bytes:", ds.Unit) // 1073741824 (GB in bytes)
}