Documentation
¶
Overview ¶
Package optional package contain primitives to work with optional data
Index ¶
- func IsPresent(mix interface{}) bool
- type Bool
- func (b Bool) Filter(f func(bool) bool) Bool
- func (b Bool) Get() bool
- func (b Bool) IfPresent(f func(bool)) Bool
- func (b Bool) IsPresent() bool
- func (b Bool) Map(f func(bool) bool) Bool
- func (b Bool) MapToFloat64(f func(bool) float64) Float64
- func (b Bool) MapToInt(f func(bool) int) Int
- func (b Bool) MapToString(f func(bool) string) String
- func (b Bool) MarshalJSON() (text []byte, err error)
- func (b Bool) MarshalYAML() (interface{}, error)
- func (b Bool) OrElse(els bool) bool
- func (b Bool) OrFalse() bool
- func (b *Bool) Scan(src interface{}) error
- func (b Bool) String() string
- func (b *Bool) UnmarshalJSON(text []byte) error
- func (b *Bool) UnmarshalText(bts []byte) error
- func (b *Bool) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Duration
- func (d Duration) Filter(f func(time.Duration) bool) Duration
- func (d Duration) FilterZero() Duration
- func (d Duration) Get() time.Duration
- func (d Duration) IfPresent(f func(time.Duration)) Duration
- func (d Duration) IsPresent() bool
- func (d Duration) Map(f func(time.Duration) time.Duration) Duration
- func (d Duration) OrElse(els time.Duration) time.Duration
- func (d Duration) String() string
- func (d Duration) ToMillis() Int
- func (d Duration) ToSeconds() Float64
- type DurationMillis
- func (d DurationMillis) MarshalJSON() (text []byte, err error)
- func (d DurationMillis) MarshalYAML() (interface{}, error)
- func (d *DurationMillis) Scan(src interface{}) error
- func (d *DurationMillis) UnmarshalJSON(text []byte) error
- func (d *DurationMillis) UnmarshalText(bts []byte) error
- func (d *DurationMillis) UnmarshalYAML(unmarshal func(interface{}) error) error
- type DurationMinutes
- func (d DurationMinutes) MarshalJSON() (text []byte, err error)
- func (d DurationMinutes) MarshalYAML() (interface{}, error)
- func (d *DurationMinutes) Scan(src interface{}) error
- func (d *DurationMinutes) UnmarshalJSON(text []byte) error
- func (d *DurationMinutes) UnmarshalText(bts []byte) error
- func (d *DurationMinutes) UnmarshalYAML(unmarshal func(interface{}) error) error
- type DurationSeconds
- func (d DurationSeconds) MarshalJSON() (text []byte, err error)
- func (d DurationSeconds) MarshalYAML() (interface{}, error)
- func (d *DurationSeconds) Scan(src interface{}) error
- func (d *DurationSeconds) UnmarshalJSON(text []byte) error
- func (d *DurationSeconds) UnmarshalText(bts []byte) error
- func (d *DurationSeconds) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Error
- type Float64
- func (f Float64) Filter(c func(float64) bool) Float64
- func (f Float64) FilterZero() Float64
- func (f Float64) Get() float64
- func (f Float64) IfPresent(c func(float64)) Float64
- func (f Float64) IsPresent() bool
- func (f Float64) Map(c func(float64) float64) Float64
- func (f Float64) MapToBool(c func(float64) bool) Bool
- func (f Float64) MapToInt(c func(float64) int) Int
- func (f Float64) MapToString(c func(float64) string) String
- func (f Float64) MarshalJSON() (text []byte, err error)
- func (f Float64) MarshalYAML() (interface{}, error)
- func (f Float64) OrElse(els float64) float64
- func (f *Float64) Scan(src interface{}) error
- func (f Float64) String() string
- func (f *Float64) UnmarshalJSON(text []byte) error
- func (f *Float64) UnmarshalText(bts []byte) error
- func (f *Float64) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Int
- func (i Int) Filter(f func(int) bool) Int
- func (i Int) FilterZero() Int
- func (i Int) Get() int
- func (i Int) IfPresent(f func(int)) Int
- func (i Int) IsPresent() bool
- func (i Int) Map(f func(int) int) Int
- func (i Int) MapToBool(f func(int) bool) Bool
- func (i Int) MapToFloat64(f func(int) float64) Float64
- func (i Int) MapToString(f func(int) string) String
- func (i Int) MarshalJSON() (text []byte, err error)
- func (i Int) MarshalYAML() (interface{}, error)
- func (i Int) OrElse(els int) int
- func (i *Int) Scan(src interface{}) error
- func (i Int) String() string
- func (i Int) ToDurationSeconds() DurationSeconds
- func (i Int) ToString() String
- func (i *Int) UnmarshalJSON(text []byte) error
- func (i *Int) UnmarshalText(bts []byte) error
- func (i *Int) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Mixed
- func (m Mixed) Filter(f func(interface{}) bool) Mixed
- func (m Mixed) Get() interface{}
- func (m Mixed) IfPresent(f func(interface{})) Mixed
- func (m Mixed) IsPresent() bool
- func (m Mixed) Map(f func(interface{}) interface{}) Mixed
- func (m Mixed) MapToBool(f func(interface{}) bool) Bool
- func (m Mixed) MapToFloat64(f func(interface{}) float64) Float64
- func (m Mixed) MapToInt(f func(interface{}) int) Int
- func (m Mixed) MapToString(f func(interface{}) string) String
- func (m Mixed) OrElse(els interface{}) interface{}
- type Optional
- type Scanner
- type String
- func (s String) Filter(f func(string) bool) String
- func (s String) FilterEmpty() String
- func (s String) Get() string
- func (s String) IfPresent(f func(string)) String
- func (s String) IsPresent() bool
- func (s String) Map(f func(string) string) String
- func (s String) MapToBool(f func(string) bool) Bool
- func (s String) MapToFloat64(f func(string) float64) Float64
- func (s String) MapToInt(f func(string) int) Int
- func (s String) MarshalJSON() (text []byte, err error)
- func (s String) MarshalYAML() (interface{}, error)
- func (s String) OrElse(els string) string
- func (s *String) Scan(src interface{}) error
- func (s String) String() string
- func (s String) Trim() String
- func (s *String) UnmarshalJSON(text []byte) error
- func (s *String) UnmarshalText(bts []byte) error
- func (s *String) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Time
- func (t Time) Filter(f func(time.Time) bool) Time
- func (t Time) FilterZero() Time
- func (t Time) Get() time.Time
- func (t Time) IfPresent(f func(time.Time)) Time
- func (t Time) IsPresent() bool
- func (t Time) Map(f func(time.Time) time.Time) Time
- func (t Time) OrElse(els time.Time) time.Time
- func (t Time) OrNow() time.Time
- func (t Time) String() string
- func (t Time) ToUnixMillis() Int
- func (t Time) ToUnixSeconds() Int
- type TimeUnixSeconds
- func (t TimeUnixSeconds) MarshalJSON() (text []byte, err error)
- func (t TimeUnixSeconds) MarshalYAML() (interface{}, error)
- func (t *TimeUnixSeconds) Scan(src interface{}) error
- func (t *TimeUnixSeconds) UnmarshalJSON(text []byte) error
- func (t *TimeUnixSeconds) UnmarshalText(bts []byte) error
- func (t *TimeUnixSeconds) UnmarshalYAML(unmarshal func(interface{}) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool represents optional boolean value
func (Bool) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Bool) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: invalid memory address or nil pointer dereference Perform .IsPresent check or use .OrElse to avoid manic
func (Bool) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
func (Bool) MapToFloat64 ¶
MapToFloat64 applies mapping function on optional value if it presents
func (Bool) MapToString ¶
MapToString applies mapping function on optional value if it presents
func (Bool) MarshalJSON ¶
MarshalJSON is json.Marshaler interface implementation
func (Bool) MarshalYAML ¶
MarshalYAML is yaml.Marshaler interface implementation
func (Bool) OrFalse ¶
OrFalse returns false for empty optional value For other cases it will return optional value
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON is json.Unmarshaler interface implementation
func (*Bool) UnmarshalText ¶
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*Bool) UnmarshalYAML ¶
UnmarshalYAML is yaml.Unmarshaler interface implementation
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration represents optional duration value
func OfDuration ¶
OfDuration creates new optional time.Duration containing provided value
func OfDurationRef ¶
OfDurationRef creates new optional time.Duration containing provided value
func (Duration) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Duration) FilterZero ¶
FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing
func (Duration) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: invalid memory address or nil pointer dereference Perform .IsPresent check or use .OrElse to avoid manic
func (Duration) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
type DurationMillis ¶
type DurationMillis struct {
Duration
}
DurationMillis is wrapper over Duration to be used in JSON and SQL mappers
func OfMilliseconds ¶
func OfMilliseconds(millis int) DurationMillis
OfMilliseconds creates new optional time.Duration containing provided duration in milliseconds
func OfMillisecondsRef ¶
func OfMillisecondsRef(millis *int) DurationMillis
OfMillisecondsRef creates new optional time.Duration containing provided duration in milliseconds
func (DurationMillis) MarshalJSON ¶
func (d DurationMillis) MarshalJSON() (text []byte, err error)
MarshalJSON is json.Marshaler interface implementation
func (DurationMillis) MarshalYAML ¶
func (d DurationMillis) MarshalYAML() (interface{}, error)
MarshalYAML is yaml.Marshaler interface implementation
func (*DurationMillis) Scan ¶
func (d *DurationMillis) Scan(src interface{}) error
Scan is sql.Scanner interface implementation
func (*DurationMillis) UnmarshalJSON ¶
func (d *DurationMillis) UnmarshalJSON(text []byte) error
UnmarshalJSON is json.Unmarshaler interface implementation
func (*DurationMillis) UnmarshalText ¶
func (d *DurationMillis) UnmarshalText(bts []byte) error
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*DurationMillis) UnmarshalYAML ¶
func (d *DurationMillis) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML is yaml.Unmarshaler interface implementation
type DurationMinutes ¶
type DurationMinutes struct {
Duration
}
DurationMinutes is wrapper over Duration to be used in JSON and SQL mappers
func OfMinutes ¶
func OfMinutes(minutes int) DurationMinutes
OfMinutes creates new optional time.Duration containing provided duration in minutes
func OfMinutesRef ¶
func OfMinutesRef(minutes *int) DurationMinutes
OfMinutesRef creates new optional time.Duration containing provided duration in minutes
func (DurationMinutes) MarshalJSON ¶
func (d DurationMinutes) MarshalJSON() (text []byte, err error)
MarshalJSON is json.Marshaler interface implementation
func (DurationMinutes) MarshalYAML ¶
func (d DurationMinutes) MarshalYAML() (interface{}, error)
MarshalYAML is yaml.Marshaler interface implementation
func (*DurationMinutes) Scan ¶
func (d *DurationMinutes) Scan(src interface{}) error
Scan is sql.Scanner interface implementation
func (*DurationMinutes) UnmarshalJSON ¶
func (d *DurationMinutes) UnmarshalJSON(text []byte) error
UnmarshalJSON is json.Unmarshaler interface implementation
func (*DurationMinutes) UnmarshalText ¶
func (d *DurationMinutes) UnmarshalText(bts []byte) error
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*DurationMinutes) UnmarshalYAML ¶
func (d *DurationMinutes) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML is yaml.Unmarshaler interface implementation
type DurationSeconds ¶
type DurationSeconds struct {
Duration
}
DurationSeconds is wrapper over Duration to be used in JSON and SQL mappers
func OfSeconds ¶
func OfSeconds(sec int) DurationSeconds
OfSeconds creates new optional time.Duration containing provided duration in seconds
func OfSecondsRef ¶
func OfSecondsRef(sec *int) DurationSeconds
OfSecondsRef creates new optional time.Duration containing provided duration in seconds
func (DurationSeconds) MarshalJSON ¶
func (d DurationSeconds) MarshalJSON() (text []byte, err error)
MarshalJSON is json.Marshaler interface implementation
func (DurationSeconds) MarshalYAML ¶
func (d DurationSeconds) MarshalYAML() (interface{}, error)
MarshalYAML is yaml.Marshaler interface implementation
func (*DurationSeconds) Scan ¶
func (d *DurationSeconds) Scan(src interface{}) error
Scan is sql.Scanner interface implementation
func (*DurationSeconds) UnmarshalJSON ¶
func (d *DurationSeconds) UnmarshalJSON(text []byte) error
UnmarshalJSON is json.Unmarshaler interface implementation
func (*DurationSeconds) UnmarshalText ¶
func (d *DurationSeconds) UnmarshalText(bts []byte) error
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*DurationSeconds) UnmarshalYAML ¶
func (d *DurationSeconds) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML is yaml.Unmarshaler interface implementation
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is optional container for errors
func (Error) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Error) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: nil in optional.Error Perform .IsPresent check or use .OrElse to avoid manic
func (Error) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
type Float64 ¶
type Float64 struct {
// contains filtered or unexported fields
}
Float64 contains optional float64 value
func OfFloat64Ref ¶
OfFloat64Ref creates new optional float64 containing provided value
func (Float64) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Float64) FilterZero ¶
FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing
func (Float64) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: invalid memory address or nil pointer dereference Perform .IsPresent check or use .OrElse to avoid manic
func (Float64) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
func (Float64) MapToString ¶
MapToString applies mapping function on optional value if it presents
func (Float64) MarshalJSON ¶
MarshalJSON is json.Marshaler interface implementation
func (Float64) MarshalYAML ¶
MarshalYAML is yaml.Marshaler interface implementation
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON is json.Unmarshaler interface implementation
func (*Float64) UnmarshalText ¶
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*Float64) UnmarshalYAML ¶
UnmarshalYAML is yaml.Unmarshaler interface implementation
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int represents optional integer value
func (Int) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Int) FilterZero ¶
FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing
func (Int) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: invalid memory address or nil pointer dereference Perform .IsPresent check or use .OrElse to avoid manic
func (Int) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
func (Int) MapToFloat64 ¶
MapToFloat64 applies mapping function on optional value if it presents
func (Int) MapToString ¶
MapToString applies mapping function on optional value if it presents
func (Int) MarshalJSON ¶
MarshalJSON is json.Marshaler interface implementation
func (Int) MarshalYAML ¶
MarshalYAML is yaml.Marshaler interface implementation
func (Int) ToDurationSeconds ¶
func (i Int) ToDurationSeconds() DurationSeconds
ToDurationSeconds return optional time.Duration, built from value of optional int
func (*Int) UnmarshalJSON ¶
UnmarshalJSON is json.Unmarshaler interface implementation
func (*Int) UnmarshalText ¶
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*Int) UnmarshalYAML ¶
UnmarshalYAML is yaml.Unmarshaler interface implementation
type Mixed ¶
type Mixed struct {
// contains filtered or unexported fields
}
Mixed represents arbitrary interface{} optional
func OfMixed ¶
func OfMixed(src interface{}) Mixed
OfMixed creates new optional interface{} holder containing provided value
func (Mixed) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Mixed) Get ¶
func (m Mixed) Get() interface{}
Get returns value from optional. Invocation on empty optional will cause panic: nil in mixed value Perform .IsPresent check or use .OrElse to avoid manic
func (Mixed) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
func (Mixed) MapToFloat64 ¶
MapToFloat64 applies mapping function on optional value if it presents
func (Mixed) MapToString ¶
MapToString applies mapping function on optional value if it presents
type Optional ¶
type Optional interface {
IsPresent() bool
}
Optional is minimal non-generic interface for optional data holders
type Scanner ¶
type Scanner interface {
Optional
Scan(interface{}) error
MarshalJSON() ([]byte, error)
UnmarshalJSON([]byte) error
}
Scanner represents subset of optional values, that supports mapping from SQL and JSON
type String ¶
type String struct {
// contains filtered or unexported fields
}
String contains optional string value
func OfStringRef ¶
OfStringRef creates new optional string containing provided value
func (String) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (String) FilterEmpty ¶
FilterEmpty applies empty (but not whitespace) filtering and returns optional
func (String) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: invalid memory address or nil pointer dereference Perform .IsPresent check or use .OrElse to avoid manic
func (String) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
func (String) MapToFloat64 ¶
MapToFloat64 applies mapping function on optional value if it presents
func (String) MarshalJSON ¶
MarshalJSON is json.Marshaler interface implementation
func (String) MarshalYAML ¶
MarshalYAML is yaml.Marshaler interface implementation
func (*String) UnmarshalJSON ¶
UnmarshalJSON is json.Unmarshaler interface implementation
func (*String) UnmarshalText ¶
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*String) UnmarshalYAML ¶
UnmarshalYAML is yaml.Unmarshaler interface implementation
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time represents optional time value
func (Time) Filter ¶
Filter method applies predicate on optional content Resulting optional will be non empty only if predicate returns true and original value inside optional was not empty.
func (Time) FilterZero ¶
FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing
func (Time) Get ¶
Get returns value from optional. Invocation on empty optional will cause panic: invalid memory address or nil pointer dereference Perform .IsPresent check or use .OrElse to avoid manic
func (Time) IfPresent ¶
IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked
func (Time) ToUnixMillis ¶
ToUnixMillis return optional int, built from value of optional time If optional was not empty, resulting optional int will contain unix timestamp in milliseconds
func (Time) ToUnixSeconds ¶
ToUnixSeconds return optional int, built from value of optional time If optional was not empty, resulting optional int will contain unix timestamp in seconds
type TimeUnixSeconds ¶
type TimeUnixSeconds struct {
Time
}
TimeUnixSeconds is wrapper over Time to be used in JSON and SQL mappers
func OfUnixSeconds ¶
func OfUnixSeconds(sec int) TimeUnixSeconds
OfUnixSeconds creates new optional time.Time containing provided unix timestamp in seconds
func OfUnixSecondsRef ¶
func OfUnixSecondsRef(sec *int) TimeUnixSeconds
OfUnixSecondsRef creates new optional time.Time containing provided unix timestamp in seconds
func (TimeUnixSeconds) MarshalJSON ¶
func (t TimeUnixSeconds) MarshalJSON() (text []byte, err error)
MarshalJSON is json.Marshaler interface implementation
func (TimeUnixSeconds) MarshalYAML ¶
func (t TimeUnixSeconds) MarshalYAML() (interface{}, error)
MarshalYAML is yaml.Marshaler interface implementation
func (*TimeUnixSeconds) Scan ¶
func (t *TimeUnixSeconds) Scan(src interface{}) error
Scan is sql.Scanner interface implementation
func (*TimeUnixSeconds) UnmarshalJSON ¶
func (t *TimeUnixSeconds) UnmarshalJSON(text []byte) error
UnmarshalJSON is json.Unmarshaler interface implementation
func (*TimeUnixSeconds) UnmarshalText ¶
func (t *TimeUnixSeconds) UnmarshalText(bts []byte) error
UnmarshalText is encoding.TextUnmarshaler interface implementation
func (*TimeUnixSeconds) UnmarshalYAML ¶
func (t *TimeUnixSeconds) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML is yaml.Unmarshaler interface implementation