cor

package
v0.0.0-...-7e8a755 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: BSD-2-Clause Imports: 8 Imported by: 18

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

Constants

This section is empty.

Variables

View Source
var (
	Error  = xerrors.New
	Errorf = xerrors.Errorf
)

centralize access to error api that is going to change in go 1.13

View Source
var ErrSpan = StrError("invalid span format")

ErrSpan indicates an invalid input format when parsing a span.

View Source
var ErrUUID = StrError("invalid uuid format")

ErrUUID indicates an invalid input format when parsing an uuid.

Functions

func Any

func Any(v interface{}) *interface{}

Any returns a pointer to v.

func Bool

func Bool(v bool) *bool

Bool returns a pointer to v.

func Cased

func Cased(n string) (s string)

Cased returns n starting with uppercase letter. This function is especially used for go code gen.

func Digit

func Digit(r rune) bool

Digit tests whether r is an ascii digit.

func FormatHex

func FormatHex(v []byte) string

FormatHex returns v as string starting with '\x' and followed by the bytes as lower hex.

func FormatRaw

func FormatRaw(v []byte) string

FormatRaw returns v as string, plain texts are returned as is, otherwise FormatHex is used.

func FormatSpan

func FormatSpan(v time.Duration) string

FormatSpan returns v in the string format '-123:04:05.678'.

func FormatTime

func FormatTime(v time.Time) string

FormatTime returns v as string in the RFC3339 format with milliseconds.

func FormatUUID

func FormatUUID(v [16]byte) string

FormatUUID returns v as string in the canonical uuid format.

func Int

func Int(v int64) *int64

Int returns a pointer to v.

func IsErr

func IsErr(err, e error) bool

func IsKey

func IsKey(s string) bool

IsKey tests whether s is a valid key.

func IsName

func IsName(s string) bool

IsName tests whether s is a valid name.

func KeyPart

func KeyPart(r rune) bool

KeyPart tests whether r is ascii lowercase letter, digit, dot or underscore.

func KeyStart

func KeyStart(r rune) bool

KeyStart tests whether r is ascii lowercase letter or underscore.

func Keyed

func Keyed(s string) string

Keyed returns the s starting with the first name segment as key.

func Keyify

func Keyify(s string) string

func LastKey

func LastKey(s string) string

LastKey returns the last name segment of s as key.

func LastName

func LastName(s string) string

LastName returns the last name segment of s.

func Letter

func Letter(r rune) bool

Letter tests whether r is an ascii letter.

func Milli

func Milli(v time.Duration) int64

Milli returns the milliseconds in v as integer.

func MilliSpan

func MilliSpan(n int64) time.Duration

MilliSpan returns milliseconds n as time duration.

func NamePart

func NamePart(r rune) bool

NamePart tests whether r is ascii letter, digit or underscore.

func NameStart

func NameStart(r rune) bool

NameStart tests whether r is ascii letter or underscore.

func ParseRaw

func ParseRaw(s string) ([]byte, error)

ParseRaw parses s and returns a byte slice or an error.

func ParseSpan

func ParseSpan(s string) (time.Duration, error)

ParseSpan parses s and returns a time duration or an error. It accepts two formats '-123h4m5s678ms' and '-123:04:05.678'.

func ParseTime

func ParseTime(s string) (time.Time, error)

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

func ParseTimeFormat(s, fmt string) (time.Time, error)

ParseTimeFormat parses s with go time fmt in the local timezone and returns a time or error.

func ParseUUID

func ParseUUID(s string) ([16]byte, error)

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 Punct

func Punct(r rune) bool

Punct tests whether r is one of the ascii punctuations allowed in symbols.

func Quote

func Quote(s string, q byte) (string, error)

Quote is a json compatible string quoter that works for single and double quotes and back ticks.

func Raw

func Raw(s string) *[]byte

Raw parses s and returns a pointer to a byte slice or nil on error.

func Real

func Real(v float64) *float64

Real returns a pointer to v.

func Space

func Space(r rune) bool

Space tests whether r is a space, tab or newline.

func Span

func Span(s string) *time.Duration

Span parses s and return a pointer to a time duration or nil on error.

func Str

func Str(v string) *string

Str returns a pointer to v.

func StrError

func StrError(str string) error

StrError returns a simple comparable error value that does not include stack information. This is usefully for lean package level error values.

func Time

func Time(s string) *time.Time

Time parses s and returns a pointer to a time or nil on error

func UUID

func UUID(s string) *[16]byte

UUID parses s and returns a pointer to the uuid bytes or nil on error.

func UnixMilli

func UnixMilli(v time.Time) int64

UnixMilli returns a integer timestamp since unix epoch in milliseconds.

func UnixMilliTime

func UnixMilliTime(n int64) time.Time

UnixMilliTime constructs and returns a time from the millisecond timestamp since unix epoch.

func Unquote

func Unquote(s string) (string, error)

Unquote is a stripped version of strconv.Unquote. It does not complain about single-quoted string having length greater than 1.

Types

This section is empty.

Jump to

Keyboard shortcuts

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