optional

package module
v0.0.0-...-d839125 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: MIT Imports: 8 Imported by: 0

README ¶

Summary

Build Status Go Report Card

This library has two major goals:

  1. Provide data types to be used during incoming and outgoing data mapping for optional values
  2. Provide safe and sufficient mapping functions to work with optional values

TL&DR;

Simple declare optional. data type in your struct

type Configuration struct {
    Hostname optional.String `json:"hostname"`
    Port     optional.Int    `json:"port"`
}

func main() {
    bts, err := ioutil.ReadFile("config.json")
    if err != nil {
        panic(err)
    }
    var c Configuration
    if err := json.Unmarshal(bts, &v); err != nil {
        panic(err)
    }

    host := c.Hostname.OrElse("localhost")
    port := c.Port.OrElse(3306)
}

Features

Supported mapping:
Data types, all of them are immutable:
  • optional.Bool - for booleans
  • optional.Int - for integers
  • optional.String - for strings
  • optional.Float64 - for floats
  • optional.Time - for time.Time, mapping using optional.TimeUnixSeconds
  • optional.Duration - for time.Duration, mapping using optional.DurationSeconds, optional.DurationMillis or optional.DurationMinutes
Common methods for all data types:
  • Get - returns value from optional, but panics if optional is empty
  • OrElse(els) - returns value from optional or provided els value if optional is empty
  • IsPresent - returns true if optional contains vaue, false otherwise
  • IfPresent(func) - invokes provided func over value from optional if optional not empty
  • Filter(predicate) - applies predicate over optional value
  • MapToString(func), MapToInt(func), MapToFloat(func), MapToBool(func) - maps optional value to other type using func

Documentation ¶

Overview ¶

Package optional package contain primitives to work with optional data

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func IsPresent ¶

func IsPresent(mix interface{}) bool

IsPresent analyzes provided value for emptiness It will return false only if provided nil or empty Optional

Types ¶

type Bool ¶

type Bool struct {
	// contains filtered or unexported fields
}

Bool represents optional boolean value

func OfBool ¶

func OfBool(b bool) Bool

OfBool creates new optional boolean containing provided value

func OfBoolRef ¶

func OfBoolRef(b *bool) Bool

OfBoolRef creates new optional boolean containing provided value

func (Bool) Filter ¶

func (b Bool) Filter(f func(bool) bool) Bool

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 ¶

func (b Bool) Get() bool

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 ¶

func (b Bool) IfPresent(f func(bool)) Bool

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Bool) IsPresent ¶

func (b Bool) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Bool) Map ¶

func (b Bool) Map(f func(bool) bool) Bool

Map applies mapping function on optional value if it presents

func (Bool) MapToFloat64 ¶

func (b Bool) MapToFloat64(f func(bool) float64) Float64

MapToFloat64 applies mapping function on optional value if it presents

func (Bool) MapToInt ¶

func (b Bool) MapToInt(f func(bool) int) Int

MapToInt applies mapping function on optional value if it presents

func (Bool) MapToString ¶

func (b Bool) MapToString(f func(bool) string) String

MapToString applies mapping function on optional value if it presents

func (Bool) MarshalJSON ¶

func (b Bool) MarshalJSON() (text []byte, err error)

MarshalJSON is json.Marshaler interface implementation

func (Bool) MarshalYAML ¶

func (b Bool) MarshalYAML() (interface{}, error)

MarshalYAML is yaml.Marshaler interface implementation

func (Bool) OrElse ¶

func (b Bool) OrElse(els bool) bool

OrElse returns value from optional or provided value if optional is empty

func (Bool) OrFalse ¶

func (b Bool) OrFalse() bool

OrFalse returns false for empty optional value For other cases it will return optional value

func (*Bool) Scan ¶

func (b *Bool) Scan(src interface{}) error

Scan is sql.Scanner interface implementation

func (Bool) String ¶

func (b Bool) String() string

func (*Bool) UnmarshalJSON ¶

func (b *Bool) UnmarshalJSON(text []byte) error

UnmarshalJSON is json.Unmarshaler interface implementation

func (*Bool) UnmarshalText ¶

func (b *Bool) UnmarshalText(bts []byte) error

UnmarshalText is encoding.TextUnmarshaler interface implementation

func (*Bool) UnmarshalYAML ¶

func (b *Bool) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is yaml.Unmarshaler interface implementation

type Duration ¶

type Duration struct {
	// contains filtered or unexported fields
}

Duration represents optional duration value

func OfDuration ¶

func OfDuration(d time.Duration) Duration

OfDuration creates new optional time.Duration containing provided value

func OfDurationRef ¶

func OfDurationRef(d *time.Duration) Duration

OfDurationRef creates new optional time.Duration containing provided value

func (Duration) Filter ¶

func (d Duration) Filter(f func(time.Duration) bool) Duration

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 ¶

func (d Duration) FilterZero() Duration

FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing

func (Duration) Get ¶

func (d Duration) Get() time.Duration

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 ¶

func (d Duration) IfPresent(f func(time.Duration)) Duration

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Duration) IsPresent ¶

func (d Duration) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Duration) Map ¶

func (d Duration) Map(f func(time.Duration) time.Duration) Duration

Map applies mapping function on optional value if it presents

func (Duration) OrElse ¶

func (d Duration) OrElse(els time.Duration) time.Duration

OrElse returns value from optional or provided value if optional is empty

func (Duration) String ¶

func (d Duration) String() string

func (Duration) ToMillis ¶

func (d Duration) ToMillis() Int

ToMillis returns optional int, built from value of optional duration

func (Duration) ToSeconds ¶

func (d Duration) ToSeconds() Float64

ToSeconds returns optional float64, built from value of optional duration

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 OfError ¶

func OfError(err error) Error

OfError creates new optional error holder containing provided value

func (Error) Filter ¶

func (e Error) Filter(f func(error) bool) Error

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 ¶

func (e Error) Get() error

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 ¶

func (e Error) IfPresent(f func(error)) Error

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Error) IsPresent ¶

func (e Error) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Error) Panic ¶

func (e Error) Panic()

Panic method raises a panic if optional contains value

func (Error) String ¶

func (e Error) String() string

func (Error) Then ¶

func (e Error) Then(f func() error) Error

Then method invokes callback function only if current optional is empty This can be used for method chaining:

optional.OfError(nil).Then(...).Then(...).Then(...).Panic()

func (Error) ToString ¶

func (e Error) ToString() String

ToString returns optional string, built from value of optional error

type Float64 ¶

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 contains optional float64 value

func OfFloat64 ¶

func OfFloat64(f float64) Float64

OfFloat64 creates new optional float64 containing provided value

func OfFloat64Ref ¶

func OfFloat64Ref(f *float64) Float64

OfFloat64Ref creates new optional float64 containing provided value

func (Float64) Filter ¶

func (f Float64) Filter(c func(float64) bool) Float64

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 ¶

func (f Float64) FilterZero() Float64

FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing

func (Float64) Get ¶

func (f Float64) Get() float64

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 ¶

func (f Float64) IfPresent(c func(float64)) Float64

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Float64) IsPresent ¶

func (f Float64) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Float64) Map ¶

func (f Float64) Map(c func(float64) float64) Float64

Map applies mapping function on optional value if it presents

func (Float64) MapToBool ¶

func (f Float64) MapToBool(c func(float64) bool) Bool

MapToBool applies mapping function on optional value if it presents

func (Float64) MapToInt ¶

func (f Float64) MapToInt(c func(float64) int) Int

MapToInt applies mapping function on optional value if it presents

func (Float64) MapToString ¶

func (f Float64) MapToString(c func(float64) string) String

MapToString applies mapping function on optional value if it presents

func (Float64) MarshalJSON ¶

func (f Float64) MarshalJSON() (text []byte, err error)

MarshalJSON is json.Marshaler interface implementation

func (Float64) MarshalYAML ¶

func (f Float64) MarshalYAML() (interface{}, error)

MarshalYAML is yaml.Marshaler interface implementation

func (Float64) OrElse ¶

func (f Float64) OrElse(els float64) float64

OrElse returns value from optional or provided value if optional is empty

func (*Float64) Scan ¶

func (f *Float64) Scan(src interface{}) error

Scan is sql.Scanner interface implementation

func (Float64) String ¶

func (f Float64) String() string

func (*Float64) UnmarshalJSON ¶

func (f *Float64) UnmarshalJSON(text []byte) error

UnmarshalJSON is json.Unmarshaler interface implementation

func (*Float64) UnmarshalText ¶

func (f *Float64) UnmarshalText(bts []byte) error

UnmarshalText is encoding.TextUnmarshaler interface implementation

func (*Float64) UnmarshalYAML ¶

func (f *Float64) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is yaml.Unmarshaler interface implementation

type Int ¶

type Int struct {
	// contains filtered or unexported fields
}

Int represents optional integer value

func OfInt ¶

func OfInt(i int) Int

OfInt creates new optional integer containing provided value

func OfIntRef ¶

func OfIntRef(i *int) Int

OfIntRef creates new optional integer containing provided value

func (Int) Filter ¶

func (i Int) Filter(f func(int) bool) Int

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 ¶

func (i Int) FilterZero() Int

FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing

func (Int) Get ¶

func (i Int) Get() int

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 ¶

func (i Int) IfPresent(f func(int)) Int

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Int) IsPresent ¶

func (i Int) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Int) Map ¶

func (i Int) Map(f func(int) int) Int

Map applies mapping function on optional value if it presents

func (Int) MapToBool ¶

func (i Int) MapToBool(f func(int) bool) Bool

MapToBool applies mapping function on optional value if it presents

func (Int) MapToFloat64 ¶

func (i Int) MapToFloat64(f func(int) float64) Float64

MapToFloat64 applies mapping function on optional value if it presents

func (Int) MapToString ¶

func (i Int) MapToString(f func(int) string) String

MapToString applies mapping function on optional value if it presents

func (Int) MarshalJSON ¶

func (i Int) MarshalJSON() (text []byte, err error)

MarshalJSON is json.Marshaler interface implementation

func (Int) MarshalYAML ¶

func (i Int) MarshalYAML() (interface{}, error)

MarshalYAML is yaml.Marshaler interface implementation

func (Int) OrElse ¶

func (i Int) OrElse(els int) int

OrElse returns value from optional or provided value if optional is empty

func (*Int) Scan ¶

func (i *Int) Scan(src interface{}) error

Scan is sql.Scanner interface implementation

func (Int) String ¶

func (i Int) String() string

func (Int) ToDurationSeconds ¶

func (i Int) ToDurationSeconds() DurationSeconds

ToDurationSeconds return optional time.Duration, built from value of optional int

func (Int) ToString ¶

func (i Int) ToString() String

ToString returns optional string, built from value of optional int

func (*Int) UnmarshalJSON ¶

func (i *Int) UnmarshalJSON(text []byte) error

UnmarshalJSON is json.Unmarshaler interface implementation

func (*Int) UnmarshalText ¶

func (i *Int) UnmarshalText(bts []byte) error

UnmarshalText is encoding.TextUnmarshaler interface implementation

func (*Int) UnmarshalYAML ¶

func (i *Int) UnmarshalYAML(unmarshal func(interface{}) error) error

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 ¶

func (m Mixed) Filter(f func(interface{}) bool) Mixed

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 ¶

func (m Mixed) IfPresent(f func(interface{})) Mixed

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Mixed) IsPresent ¶

func (m Mixed) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Mixed) Map ¶

func (m Mixed) Map(f func(interface{}) interface{}) Mixed

Map applies mapping function on optional value if it presents

func (Mixed) MapToBool ¶

func (m Mixed) MapToBool(f func(interface{}) bool) Bool

MapToBool applies mapping function on optional value if it presents

func (Mixed) MapToFloat64 ¶

func (m Mixed) MapToFloat64(f func(interface{}) float64) Float64

MapToFloat64 applies mapping function on optional value if it presents

func (Mixed) MapToInt ¶

func (m Mixed) MapToInt(f func(interface{}) int) Int

MapToInt applies mapping function on optional value if it presents

func (Mixed) MapToString ¶

func (m Mixed) MapToString(f func(interface{}) string) String

MapToString applies mapping function on optional value if it presents

func (Mixed) OrElse ¶

func (m Mixed) OrElse(els interface{}) interface{}

OrElse returns value from optional or provided value if optional is empty

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 OfString ¶

func OfString(s string) String

OfString creates new optional string containing provided value

func OfStringRef ¶

func OfStringRef(s *string) String

OfStringRef creates new optional string containing provided value

func (String) Filter ¶

func (s String) Filter(f func(string) bool) String

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 ¶

func (s String) FilterEmpty() String

FilterEmpty applies empty (but not whitespace) filtering and returns optional

func (String) Get ¶

func (s String) Get() string

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 ¶

func (s String) IfPresent(f func(string)) String

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (String) IsPresent ¶

func (s String) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (String) Map ¶

func (s String) Map(f func(string) string) String

Map applies mapping function on optional value if it presents

func (String) MapToBool ¶

func (s String) MapToBool(f func(string) bool) Bool

MapToBool applies mapping function on optional value if it presents

func (String) MapToFloat64 ¶

func (s String) MapToFloat64(f func(string) float64) Float64

MapToFloat64 applies mapping function on optional value if it presents

func (String) MapToInt ¶

func (s String) MapToInt(f func(string) int) Int

MapToInt applies mapping function on optional value if it presents

func (String) MarshalJSON ¶

func (s String) MarshalJSON() (text []byte, err error)

MarshalJSON is json.Marshaler interface implementation

func (String) MarshalYAML ¶

func (s String) MarshalYAML() (interface{}, error)

MarshalYAML is yaml.Marshaler interface implementation

func (String) OrElse ¶

func (s String) OrElse(els string) string

OrElse returns value from optional or provided value if optional is empty

func (*String) Scan ¶

func (s *String) Scan(src interface{}) error

Scan is sql.Scanner interface implementation

func (String) String ¶

func (s String) String() string

func (String) Trim ¶

func (s String) Trim() String

Trim applies whitespace trim mapping and returns optional with new value

func (*String) UnmarshalJSON ¶

func (s *String) UnmarshalJSON(text []byte) error

UnmarshalJSON is json.Unmarshaler interface implementation

func (*String) UnmarshalText ¶

func (s *String) UnmarshalText(bts []byte) error

UnmarshalText is encoding.TextUnmarshaler interface implementation

func (*String) UnmarshalYAML ¶

func (s *String) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is yaml.Unmarshaler interface implementation

type Time ¶

type Time struct {
	// contains filtered or unexported fields
}

Time represents optional time value

func OfTime ¶

func OfTime(t time.Time) Time

OfTime creates new optional time.Time containing provided value

func OfTimeRef ¶

func OfTimeRef(t *time.Time) Time

OfTimeRef creates new optional time.Time containing provided value

func (Time) Filter ¶

func (t Time) Filter(f func(time.Time) bool) Time

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 ¶

func (t Time) FilterZero() Time

FilterZero applies zero value filtering This method will return empty optional if value inside optional is zero or missing

func (Time) Get ¶

func (t Time) Get() time.Time

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 ¶

func (t Time) IfPresent(f func(time.Time)) Time

IfPresent invokes provided callback if optional contains some value If optional is empty, callback will not be invoked

func (Time) IsPresent ¶

func (t Time) IsPresent() bool

IsPresent returns true if optional contains value and false for null

func (Time) Map ¶

func (t Time) Map(f func(time.Time) time.Time) Time

Map applies mapping function on optional value if it presents

func (Time) OrElse ¶

func (t Time) OrElse(els time.Time) time.Time

OrElse returns value from optional or provided value if optional is empty

func (Time) OrNow ¶

func (t Time) OrNow() time.Time

OrNow returns value from optional or current time if optional is empty

func (Time) String ¶

func (t Time) String() string

func (Time) ToUnixMillis ¶

func (t Time) ToUnixMillis() Int

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 ¶

func (t Time) ToUnixSeconds() Int

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

Jump to

Keyboard shortcuts

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