Documentation ¶
Index ¶
- Constants
- Variables
- func DateFromString(env Environment, str string) (time.Time, error)
- func DateToISO(date time.Time) string
- func DateToString(env Environment, date time.Time) string
- func DateToUTCRange(d time.Time, tz *time.Location) (time.Time, time.Time)
- func DaysBetween(date1 time.Time, date2 time.Time) int
- func IsNil(v interface{}) bool
- func JSONMarshal(v interface{}) ([]byte, error)
- func JSONMarshalPretty(v interface{}) ([]byte, error)
- func MinInt(x, y int) int
- func MonthsBetween(date1 time.Time, date2 time.Time) int
- func NewSeededRand(seed int64) *rand.Rand
- func RandDecimal() decimal.Decimal
- func RandIntN(n int) int
- func SetRand(rnd *rand.Rand)
- func SetUUIDGenerator(generator UUIDGenerator)
- func Snakify(text string) string
- func ToGoDateFormat(format string) (string, error)
- func TokenizeString(str string) []string
- func UnmarshalAndValidate(data []byte, obj interface{}, objName string) error
- func UnmarshalArray(data json.RawMessage) ([]json.RawMessage, error)
- func Validate(obj interface{}) error
- func ValidateAs(obj interface{}, objName string) error
- func ValidateDateTimeFormat(fl validator.FieldLevel) bool
- type DateFormat
- type Environment
- type HTTPClient
- type Language
- type LanguageList
- type Location
- type LocationHierarchy
- type LocationLevel
- type RedactionPolicy
- type SeededUUID4Generator
- type TimeFormat
- type Typed
- type TypedEnvelope
- type UUID
- type UUIDGenerator
- type ValidationErrors
Constants ¶
const ( DateFormatYearMonthDay DateFormat = "YYYY-MM-DD" DateFormatMonthDayYear DateFormat = "MM-DD-YYYY" DateFormatDayMonthYear DateFormat = "DD-MM-YYYY" TimeFormatHourMinute TimeFormat = "tt:mm" TimeFormatHourMinuteAmPm TimeFormat = "h:mm aa" TimeFormatHourMinuteSecond TimeFormat = "tt:mm:ss" TimeFormatHourMinuteSecondAmPm TimeFormat = "h:mm:ss aa" )
standard date and time formats
const ( LocationPathSeparator = ">" LocationPaddedPathSeparator = " > " )
Variables ¶
DefaultRand is the default rand for calls to Rand()
var NilLanguage = Language("")
NilLanguage represents our nil, or unknown language
var Validator = validator.New()
Validator is our system validator, it can be shared across threads
var ZeroTime = time.Time{}
ZeroTime is our uninitialized time value
Functions ¶
func DateFromString ¶
func DateFromString(env Environment, str string) (time.Time, error)
DateFromString returns a date constructed from the passed in string, or an error if we are unable to extract one
func DateToString ¶
func DateToString(env Environment, date time.Time) string
DateToString converts the passed in time element to the right format based on the environment settings
func DateToUTCRange ¶ added in v0.4.0
DateToUTCRange returns the UTC time range of the given day
func DaysBetween ¶
DaysBetween returns the number of calendar days (an int) between the two dates. Note that if these are in different timezones then the local calendar day is used for each and the difference is calculated from that.
func IsNil ¶ added in v0.4.0
func IsNil(v interface{}) bool
IsNil returns whether the given object is nil or an interface to a nil
func JSONMarshal ¶ added in v0.9.6
JSONMarshal marshals the given object to JSON
func JSONMarshalPretty ¶ added in v0.9.6
JSONMarshalPretty marshals the given object to pretty JSON
func MonthsBetween ¶
MonthsBetween returns the number of calendar months (an int) between the two dates. Note that if these are in different timezones then the local calendar day is used for each and the difference is calculated from that.
func NewSeededRand ¶ added in v0.8.0
NewSeededRand creates a new seeded rand
func RandDecimal ¶ added in v0.8.0
RandDecimal returns a random decimal in the range [0.0, 1.0)
func SetUUIDGenerator ¶ added in v0.6.0
func SetUUIDGenerator(generator UUIDGenerator)
SetUUIDGenerator sets the generator used by UUID4()
func Snakify ¶
Snakify turns the passed in string into a context reference. We replace all whitespace characters with _ and replace any duplicate underscores
func ToGoDateFormat ¶
ToGoDateFormat converts the passed in format to a GoLang format string.
Format strings we support:
`YY` - last two digits of year 0-99 `YYYY` - four digits of your 0000-9999 `M` - month 1-12 `MM` - month 01-12 `D` - day of month, 1-31 `DD` - day of month, zero padded 0-31 `h` - hour of the day 1-12 `hh` - hour of the day 01-12 `tt` - twenty four hour of the day 01-23 `m` - minute 0-59 `mm` - minute 00-59 `s` - second 0-59 `ss` - second 00-59 `fff` - milliseconds `ffffff` - microseconds `fffffffff` - nanoseconds `aa` - am or pm `AA` - AM or PM `Z` - hour and minute offset from UTC, or Z for UTC `ZZZ` - hour and minute offset from UTC
ignored chars: ' ', ':', ',', 'T', '-', '_', '/'
func TokenizeString ¶
TokenizeString returns the words in the passed in string, split by non word characters including emojis
func UnmarshalAndValidate ¶ added in v0.4.0
UnmarshalAndValidate is a convenience function to unmarshal an object and validate it
func UnmarshalArray ¶ added in v0.4.0
func UnmarshalArray(data json.RawMessage) ([]json.RawMessage, error)
UnmarshalArray unmarshals an array of objects from the given JSON
func Validate ¶ added in v0.4.0
func Validate(obj interface{}) error
Validate will run validation on the given object and return a set of field specific errors in the format: field <fieldname> <tag specific message>
For example: "field 'flows' is required"
func ValidateAs ¶ added in v0.4.0
ValidateAs will run validation on the given object and return a set of field specific errors in the format: field <fieldname> [on <objName>] <tag specific message>
For example: "field 'flows' on 'assets' is required"
func ValidateDateTimeFormat ¶ added in v0.9.1
func ValidateDateTimeFormat(fl validator.FieldLevel) bool
Types ¶
type DateFormat ¶
type DateFormat string
DateFormat a date format string
func (DateFormat) String ¶
func (df DateFormat) String() string
type Environment ¶
type Environment interface { DateFormat() DateFormat TimeFormat() TimeFormat Timezone() *time.Location Languages() LanguageList RedactionPolicy() RedactionPolicy Now() time.Time }
Environment defines the Environment that the Excellent function is running in, this includes the timezone the user is in as well as the preferred date and time formats.
func NewDefaultEnvironment ¶
func NewDefaultEnvironment() Environment
NewDefaultEnvironment creates a new Environment with our usual defaults in the UTC timezone
func NewEnvironment ¶
func NewEnvironment(dateFormat DateFormat, timeFormat TimeFormat, timezone *time.Location, languages LanguageList, redactionPolicy RedactionPolicy) Environment
NewEnvironment creates a new Environment with the passed in date and time formats and timezone
func ReadEnvironment ¶ added in v0.4.0
func ReadEnvironment(data json.RawMessage) (Environment, error)
ReadEnvironment reads an environment from the given JSON
type HTTPClient ¶ added in v0.9.2
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient is a client for HTTP requests
func NewHTTPClient ¶ added in v0.8.0
func NewHTTPClient(defaultUserAgent string) *HTTPClient
NewHTTPClient creates a new HTTP client with our default options
func (*HTTPClient) DoWithDump ¶ added in v0.9.2
DoWithDump does the given HTTP request and returns a dump of the entire request
type Language ¶
type Language string
Language is our internal representation of a language
func ParseLanguage ¶
ParseLanguage returns a new Language for the passed in language string, or an error if not found
type LanguageList ¶ added in v0.4.0
type LanguageList []Language
LanguageList is a list of languages
func (LanguageList) RemoveDuplicates ¶ added in v0.4.0
func (ll LanguageList) RemoveDuplicates() LanguageList
RemoveDuplicates returns a new language list with duplicates removed
type Location ¶ added in v0.4.0
type Location struct {
// contains filtered or unexported fields
}
Location represents a single Location
func NewLocation ¶ added in v0.4.0
func NewLocation(level LocationLevel, name string) *Location
NewLocation creates a new location object
func (*Location) Level ¶ added in v0.4.0
func (l *Location) Level() LocationLevel
Level gets the level of this location
type LocationHierarchy ¶ added in v0.4.0
type LocationHierarchy struct {
// contains filtered or unexported fields
}
LocationHierarchy is a hierarical tree of locations
func NewLocationHierarchy ¶ added in v0.4.0
func NewLocationHierarchy(root *Location, numLevels int) *LocationHierarchy
NewLocationHierarchy cretes a new location hierarchy
func ReadLocationHierarchy ¶ added in v0.4.0
func ReadLocationHierarchy(data json.RawMessage) (*LocationHierarchy, error)
ReadLocationHierarchy reads a location hierarchy from the given JSON
func (*LocationHierarchy) FindByName ¶ added in v0.4.0
func (h *LocationHierarchy) FindByName(name string, level LocationLevel, parent *Location) []*Location
FindByName looks for all locations in the hierarchy with the given level and name or alias
func (*LocationHierarchy) FindByPath ¶ added in v0.9.6
func (h *LocationHierarchy) FindByPath(path string) *Location
FindByPath looks for a location in the hierarchy with the given path
func (*LocationHierarchy) Root ¶ added in v0.6.0
func (h *LocationHierarchy) Root() *Location
Root gets the root location of this hierarchy (typically a country)
type LocationLevel ¶ added in v0.4.0
type LocationLevel int
LocationLevel is a numeric level, e.g. 0 = country, 1 = state
type RedactionPolicy ¶ added in v0.10.5
type RedactionPolicy string
const ( RedactionPolicyNone RedactionPolicy = "none" RedactionPolicyURNs RedactionPolicy = "urns" )
type SeededUUID4Generator ¶ added in v0.6.0
type SeededUUID4Generator struct {
// contains filtered or unexported fields
}
SeededUUID4Generator generates a seedable random v4 UUID using math/rand
func NewSeededUUID4Generator ¶ added in v0.6.0
func NewSeededUUID4Generator(seed int64) *SeededUUID4Generator
NewSeededUUID4Generator creates a new SeededUUID4Generator from the given seed
func (*SeededUUID4Generator) Next ¶ added in v0.6.0
func (g *SeededUUID4Generator) Next() UUID
Next returns the next random UUID
type TimeFormat ¶
type TimeFormat string
TimeFormat a time format string
func (TimeFormat) String ¶
func (tf TimeFormat) String() string
type Typed ¶
type Typed interface {
Type() string
}
Typed is an interface of objects that are marshalled as typed envelopes
type TypedEnvelope ¶
TypedEnvelope represents a json blob with a type property
func EnvelopeFromTyped ¶
func EnvelopeFromTyped(typed Typed) (*TypedEnvelope, error)
EnvelopeFromTyped marshals the give object into a typed envelope
func (*TypedEnvelope) MarshalJSON ¶
func (e *TypedEnvelope) MarshalJSON() ([]byte, error)
MarshalJSON marshals this envelope into JSON
func (*TypedEnvelope) UnmarshalJSON ¶
func (e *TypedEnvelope) UnmarshalJSON(b []byte) (err error)
UnmarshalJSON unmarshals a typed envelope from the given JSON
type UUIDGenerator ¶ added in v0.6.0
type UUIDGenerator interface {
Next() UUID
}
UUIDGenerator is something that can generate a UUID
var DefaultUUIDGenerator UUIDGenerator = defaultUUID4Generator{}
DefaultUUIDGenerator is the default generator for calls to NewUUID
type ValidationErrors ¶ added in v0.4.0
type ValidationErrors []error
ValidationErrors combines multiple validation errors as a single error
func (ValidationErrors) Error ¶ added in v0.4.0
func (e ValidationErrors) Error() string
Error returns a string representation of these validation errors