pct

package
v0.0.0-...-6861553 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL