uint.go 456 字节
Newer Older
T
TommyLike 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
package optional

type Uint struct {
	isSet bool
	value uint
}

func NewUint(value uint) Uint {
	return Uint{
		true,
		value,
	}
}

// EmptyUint returns a new Uint that does not have a value set.
func EmptyUint() Uint {
	return Uint{
		false,
		0,
	}
}

func (i Uint) IsSet() bool {
	return i.isSet
}

func (i Uint) Value() uint {
	return i.value
}

func (i Uint) Default(defaultValue uint) uint {
	if i.isSet {
		return i.value
	}
	return defaultValue
}