Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InvalidPercentageStringError ¶
type InvalidPercentageStringError struct {
String string
}
InvalidPercentageStringError is returned when parsing an invalid percentage string.
func (InvalidPercentageStringError) Error ¶
func (e InvalidPercentageStringError) Error() string
type OutOfRangeError ¶
type OutOfRangeError struct {
Float float64
}
OutOfRangeError is returned when parsing a percentage that is out of range.
func (OutOfRangeError) Error ¶
func (e OutOfRangeError) Error() string
type Percentage ¶
type Percentage float64
Percentage is a float64 between 0 and 1. It can be unmarshalled from a JSON number between 0 and 1 or a JSON string between "0%" and "100%".
func FromFloat64 ¶
func FromFloat64(f float64) (p Percentage, err error)
FromFloat64 converts a float64 to a Percentage if it is between 0 and 1.
func FromString ¶
func FromString(s string) (Percentage, error)
FromString converts a string to a Percentage if it is between "0%" and "100%".
func (Percentage) MarshalJSON ¶
func (p Percentage) MarshalJSON() ([]byte, error)
MarshalJSON encodes the Percentage as a JSON number.
func (Percentage) String ¶
func (p Percentage) String() string
func (*Percentage) UnmarshalJSON ¶
func (p *Percentage) UnmarshalJSON(b []byte) (err error)
UnmarshalJSON converts and validates a JSON string or number to a Percentage. If b is a JSON string, it must match X.X%, that is, a float between 0 and 100 encoded as a string with a trailing '%'. If b is a JSON number, it must be between 0 and 1.