Documentation ¶
Index ¶
- Constants
- Variables
- func DeriveCountryFromTel(number string) string
- func Indent(s string, prefix string) string
- func IsNil(v interface{}) bool
- func IsPossibleLocationPath(str string) bool
- func JSONDecodeGeneric(data []byte) (interface{}, error)
- func JSONMarshal(v interface{}) ([]byte, error)
- func JSONMarshalPretty(v interface{}) ([]byte, error)
- func MaxInt(x, y int) int
- func MinInt(x, y int) int
- func PrefixOverlap(s1, s2 string) int
- func ReadTypeFromJSON(data []byte) (string, error)
- func Snakify(text string) string
- func StringSliceContains(slice []string, str string, caseSensitive bool) bool
- func StringSlices(s string, indices []int) []string
- func TokenizeString(str string) []string
- func TokenizeStringByChars(str string, chars string) []string
- func UnmarshalAndValidate(data []byte, obj interface{}) error
- func UnmarshalAndValidateWithLimit(reader io.ReadCloser, s interface{}, limit int64) error
- func UnmarshalArray(data json.RawMessage) ([]json.RawMessage, error)
- func Validate(obj interface{}) error
- type Attachment
- type HTTPClient
- type Location
- type LocationHierarchy
- type LocationLevel
- type LocationPath
- type Typed
- type TypedEnvelope
- type ValidationErrors
Constants ¶
const (
LocationPathSeparator = ">"
)
Variables ¶
var Validator = validator.New()
Validator is our system validator, it can be shared across threads
Functions ¶
func DeriveCountryFromTel ¶ added in v0.14.7
DeriveCountryFromTel attempts to derive a country code (e.g. RW) from a phone number
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 IsPossibleLocationPath ¶ added in v0.32.0
IsPossibleLocationPath returns whether the given string could be a location path
func JSONDecodeGeneric ¶ added in v0.23.0
JSONDecodeGeneric decodes the given JSON as a generic map or slice
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 PrefixOverlap ¶ added in v0.14.7
PrefixOverlap returns the number of prefix characters which s1 and s2 have in common
func ReadTypeFromJSON ¶ added in v0.22.0
ReadTypeFromJSON reads a field called `type` from the given JSON
func Snakify ¶
Snakify turns the passed in string into a context reference. We replace all whitespace characters with _ and replace any duplicate underscores
func StringSliceContains ¶ added in v0.30.2
StringSliceContains determines whether the given slice of strings contains the given string
func StringSlices ¶ added in v0.28.3
StringSlices returns the slices of s defined by pairs of indexes in indices
func TokenizeString ¶
TokenizeString returns the words in the passed in string, split by non word characters including emojis
func TokenizeStringByChars ¶ added in v0.10.17
TokenizeStringByChars returns the words in the passed in string, split by the chars in the given string
func UnmarshalAndValidate ¶ added in v0.4.0
UnmarshalAndValidate is a convenience function to unmarshal an object and validate it
func UnmarshalAndValidateWithLimit ¶ added in v0.13.1
func UnmarshalAndValidateWithLimit(reader io.ReadCloser, s interface{}, limit int64) error
UnmarshalAndValidateWithLimit unmarsmals a struct with a limit on how many bytes can be read from the given reader
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
Types ¶
type Attachment ¶ added in v0.32.0
type Attachment string
Attachment is a media attachment on a message in the format <content-type>:<url>. Content type may be a full media type or may omit the subtype when it is unknown.
Examples:
- image/jpeg:http://s3.amazon.com/bucket/test.jpg
- image:http://s3.amazon.com/bucket/test.jpg
func (Attachment) ContentType ¶ added in v0.32.0
func (a Attachment) ContentType() string
ContentType returns the MIME type of this attachment
func (Attachment) ToParts ¶ added in v0.32.0
func (a Attachment) ToParts() (string, string)
ToParts splits an attachment string into content-type and URL
func (Attachment) URL ¶ added in v0.32.0
func (a Attachment) URL() string
URL returns the full URL of this attachment
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 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
func (*Location) Path ¶ added in v0.9.6
func (l *Location) Path() LocationPath
Path gets the full path 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 LocationPath) *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)
func (*LocationHierarchy) UnmarshalJSON ¶ added in v0.22.0
func (h *LocationHierarchy) UnmarshalJSON(data []byte) error
type LocationLevel ¶ added in v0.4.0
type LocationLevel int
LocationLevel is a numeric level, e.g. 0 = country, 1 = state
type LocationPath ¶ added in v0.32.0
type LocationPath string
LocationPath is a location described by a path Country > State ...
func NewLocationPath ¶ added in v0.32.0
func NewLocationPath(parts ...string) LocationPath
func (LocationPath) Name ¶ added in v0.32.0
func (p LocationPath) Name() string
Name returns the name of the location referenced
func (LocationPath) Normalize ¶ added in v0.32.0
func (p LocationPath) Normalize() LocationPath
Normalize normalizes this location path
type Typed ¶
type Typed interface {
Type() string
}
Typed is an interface of objects that are marshalled as typed envelopes
type TypedEnvelope ¶
type TypedEnvelope struct {
Type string `json:"type" validate:"required"`
}
TypedEnvelope can be mixed into envelopes that have a type field
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