github.com/thanos-io/thanos@v0.32.5/pkg/model/units.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package model 5 6 import ( 7 "github.com/alecthomas/units" 8 ) 9 10 // Bytes is a data type which supports yaml serialization/deserialization 11 // with units. 12 type Bytes uint64 13 14 func (b *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error { 15 var value string 16 err := unmarshal(&value) 17 if err != nil { 18 return err 19 } 20 21 bytes, err := units.ParseBase2Bytes(value) 22 if err != nil { 23 return err 24 } 25 26 *b = Bytes(bytes) 27 return nil 28 } 29 30 func (b *Bytes) MarshalYAML() (interface{}, error) { 31 return units.Base2Bytes(*b).String(), nil 32 }