types/opt: add (Value[T]).GetOr(def T) T method
Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
parent
20562a4fb9
commit
bd54b61746
|
@ -64,6 +64,14 @@ func (o Value[T]) Get() T {
|
|||
return o.value
|
||||
}
|
||||
|
||||
// GetOr returns the value of o or def if a value hasn't been set.
|
||||
func (o Value[T]) GetOr(def T) T {
|
||||
if o.set {
|
||||
return o.value
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// Get returns the value and a flag indicating whether the value is set.
|
||||
func (o Value[T]) GetOk() (v T, ok bool) {
|
||||
return o.value, o.set
|
||||
|
|
Loading…
Reference in New Issue