Documentation ¶
Index ¶
- Variables
- func BytesToSize(size float64, precision uint) (string, error)
- func ValidateMeasure(format string) bool
- type ReadableSize
- func (rs *ReadableSize) Get() big.Int
- func (rs *ReadableSize) GetCompiledInMeasure(measure string) (float64, error)
- func (rs *ReadableSize) GetCompiledUInt64() uint64
- func (rs *ReadableSize) GetInput() string
- func (rs *ReadableSize) GetMeasure() int64
- func (rs *ReadableSize) GetRaw() big.Float
- func (rs ReadableSize) MarshalJSON() ([]byte, error)
- func (rs ReadableSize) MarshalYAML() (interface{}, error)
- func (rs *ReadableSize) UnmarshalJSON(source []byte) error
- func (rs *ReadableSize) UnmarshalYAML(unmarshal func(interface{}) error) error
Constants ¶
This section is empty.
Variables ¶
var ( UnsupportedFormat = errors.New("unsupported data size format") UnexpectedError = errors.New("unable convert") )
available errors
Functions ¶
func BytesToSize ¶
BytesToSize parses a number and returns a string of data size format. For example: 100MB.
func ValidateMeasure ¶
ValidateMeasure parses a data size measure and returns true or false.
Types ¶
type ReadableSize ¶
type ReadableSize struct {
// contains filtered or unexported fields
}
ReadableSize is the representation of a compiled data size expression.
func Compile ¶
func Compile(input string) (*ReadableSize, error)
Compile parses a data size expression and returns, if successful, a ReadableSize object. For example: 100MB.
func MustCompile ¶
func MustCompile(input string) *ReadableSize
MustCompile parses a data size expression and returns, if successful, a ReadableSize object or returns panic, if an error is found. For example: 100MB.
func (*ReadableSize) Get ¶
func (rs *ReadableSize) Get() big.Int
Get returns the compiled data size in big.Int.
func (*ReadableSize) GetCompiledInMeasure ¶
func (rs *ReadableSize) GetCompiledInMeasure(measure string) (float64, error)
GetCompiledInMeasure returns the compiled data size in a specific dimension. See the constant for the allowed options. WARNING: Due to the nature of rounding of floating point numbers, values may have slight deviations.
func (*ReadableSize) GetCompiledUInt64 ¶
func (rs *ReadableSize) GetCompiledUInt64() uint64
GetCompiledUInt64 returns the compiled data size in uint64. Warning: Possible rounding overflow, use with relatively small numbers.
func (*ReadableSize) GetInput ¶
func (rs *ReadableSize) GetInput() string
GetInput returns original data size expression.
func (*ReadableSize) GetMeasure ¶
func (rs *ReadableSize) GetMeasure() int64
GetMeasure returns the compiled data units in uint64.
func (*ReadableSize) GetRaw ¶
func (rs *ReadableSize) GetRaw() big.Float
GetRaw returns the compiled data size.
func (ReadableSize) MarshalJSON ¶ added in v1.2.0
func (rs ReadableSize) MarshalJSON() ([]byte, error)
MarshalJSON designed to deserialize *ReadableSize to original data size expression defined in user code via the json library
func (ReadableSize) MarshalYAML ¶ added in v1.2.0
func (rs ReadableSize) MarshalYAML() (interface{}, error)
MarshalYAML designed to deserialize *ReadableSize in original data size expression defined in user code via the gopkg.in/yaml.v3 library
func (*ReadableSize) UnmarshalJSON ¶ added in v1.2.0
func (rs *ReadableSize) UnmarshalJSON(source []byte) error
UnmarshalJSON designed to serialize a string in data size expression to *ReadableSize, defined in user code via the json library
func (*ReadableSize) UnmarshalYAML ¶ added in v1.2.0
func (rs *ReadableSize) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML designed to serialize a string in data size expression to *ReadableSize, defined in user code via the gopkg.in/yaml.v3 library