Documentation ¶
Overview ¶
Package cor has some utility function for working with numeric and character literal values.
The literal values of raw, uuid, time and span all have a string parser, formatter and a parser function that returns a pointer or nil on error.
The primitive go types bool, int64, float64 and string have a function that returns a pointer to the passed in value to aid code generation for literal values.
Index ¶
- Variables
- func Any(v interface{}) *interface{}
- func Bool(v bool) *bool
- func Cased(n string) (s string)
- func Digit(r rune) bool
- func FormatHex(v []byte) string
- func FormatRaw(v []byte) string
- func FormatSpan(v time.Duration) string
- func FormatTime(v time.Time) string
- func FormatUUID(v [16]byte) string
- func Int(v int64) *int64
- func IsErr(err, e error) bool
- func IsKey(s string) bool
- func IsName(s string) bool
- func KeyPart(r rune) bool
- func KeyStart(r rune) bool
- func Keyed(s string) string
- func Keyify(s string) string
- func LastKey(s string) string
- func LastName(s string) string
- func Letter(r rune) bool
- func Milli(v time.Duration) int64
- func MilliSpan(n int64) time.Duration
- func NamePart(r rune) bool
- func NameStart(r rune) bool
- func ParseRaw(s string) ([]byte, error)
- func ParseSpan(s string) (time.Duration, error)
- func ParseTime(s string) (time.Time, error)
- func ParseTimeFormat(s, fmt string) (time.Time, error)
- func ParseUUID(s string) ([16]byte, error)
- func Punct(r rune) bool
- func Quote(s string, q byte) (string, error)
- func Raw(s string) *[]byte
- func Real(v float64) *float64
- func Space(r rune) bool
- func Span(s string) *time.Duration
- func Str(v string) *string
- func StrError(str string) error
- func Time(s string) *time.Time
- func UUID(s string) *[16]byte
- func UnixMilli(v time.Time) int64
- func UnixMilliTime(n int64) time.Time
- func Unquote(s string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( Error = xerrors.New Errorf = xerrors.Errorf )
centralize access to error api that is going to change in go 1.13
var ErrSpan = StrError("invalid span format")
ErrSpan indicates an invalid input format when parsing a span.
var ErrUUID = StrError("invalid uuid format")
ErrUUID indicates an invalid input format when parsing an uuid.
Functions ¶
func Cased ¶
Cased returns n starting with uppercase letter. This function is especially used for go code gen.
func FormatHex ¶
FormatHex returns v as string starting with '\x' and followed by the bytes as lower hex.
func FormatRaw ¶
FormatRaw returns v as string, plain texts are returned as is, otherwise FormatHex is used.
func FormatSpan ¶
FormatSpan returns v in the string format '-123:04:05.678'.
func FormatTime ¶
FormatTime returns v as string in the RFC3339 format with milliseconds.
func FormatUUID ¶
FormatUUID returns v as string in the canonical uuid format.
func ParseSpan ¶
ParseSpan parses s and returns a time duration or an error. It accepts two formats '-123h4m5s678ms' and '-123:04:05.678'.
func ParseTime ¶
ParseTime parses s and return a time or error. It accepts variations of the RFC3339 format:
2006-01-02([T ]15:04(:05:999999999)?)?(Z|[+-]07([:]?00)?)?
The returned time will be parsed in the local timezone if none is specified.
func ParseTimeFormat ¶
ParseTimeFormat parses s with go time fmt in the local timezone and returns a time or error.
func ParseUUID ¶
ParseUUID parses s and return the uuid bytes or an error. It accepts 16 hex encoded bytes with up to four dashes in between.
func Quote ¶
Quote is a json compatible string quoter that works for single and double quotes and back ticks.
func StrError ¶
StrError returns a simple comparable error value that does not include stack information. This is usefully for lean package level error values.
func UnixMilliTime ¶
UnixMilliTime constructs and returns a time from the millisecond timestamp since unix epoch.
Types ¶
This section is empty.