utils

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 16 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BooleanFalseValues = []string{`false`, `no`, `off`}
View Source
var BooleanTrueValues = []string{`true`, `yes`, `on`}
View Source
var EachChanMaxItems = 1048576
View Source
var NilStrings = []string{`null`, `NULL`, `<nil>`, `nil`, `Nil`, `None`, `undefined`, ``}
View Source
var PassthroughType = errors.New(`passthrough`)
View Source
var ReferenceTime time.Time = time.Date(2006, 1, 2, 15, 4, 5, 999999999, time.FixedZone("MST", -7*60*60))
View Source
var SliceTypes = []reflect.Kind{
	reflect.Slice,
	reflect.Array,
}
View Source
var Stop = fmt.Errorf("stop iterating")
View Source
var TimeFormats = []string{
	time.RFC3339,
	time.RFC3339Nano,
	time.ANSIC,
	time.UnixDate,
	time.RubyDate,
	time.RFC850,
	time.RFC822,
	time.RFC822Z,
	time.RFC1123,
	time.RFC1123Z,
	time.Kitchen,
	`2006-01-02 15:04:05.000000000`,
	`2006-01-02 15:04:05.000000`,
	`2006-01-02 15:04:05.000`,
	`2006-01-02 15:04:05 -0700 MST`,
	`2006-01-02 15:04:05Z07:00`,
	`2006-01-02 15:04:05`,
	`2006-01-02 15:04`,
	`2006-01-02`,
	`2006-01-02T15:04:05.000000000`,
	`2006-01-02T15:04:05.000000`,
	`2006-01-02T15:04:05.000`,
	`2006-01-02T15:04:05 -0700 MST`,
	`2006-01-02T15:04:05Z07:00`,
	`2006-01-02T15:04:05`,
	`2006-01-02T15:04`,
}

Functions

func AppendError

func AppendError(base error, err error) error

Appends on error to another, allowing for operations that return multiple errors to remain compatible within a single-valued context.

func Autotype

func Autotype(in interface{}) interface{}

func ConvertCustomType added in v1.5.55

func ConvertCustomType(in interface{}) (interface{}, error)

Returns the given value, converted according to any handlers set via RegisterTypeHandler.

func ConvertHexToInteger added in v1.7.49

func ConvertHexToInteger(in interface{}) (int64, error)

func ConvertTo

func ConvertTo(toType ConvertType, inI interface{}) (interface{}, error)

func ConvertToBool

func ConvertToBool(in interface{}) (bool, error)

func ConvertToBytes

func ConvertToBytes(in interface{}) ([]byte, error)

func ConvertToFloat

func ConvertToFloat(in interface{}) (float64, error)

func ConvertToInteger

func ConvertToInteger(in interface{}) (int64, error)

func ConvertToString

func ConvertToString(in interface{}) (string, error)

func ConvertToTime

func ConvertToTime(in interface{}) (time.Time, error)

func DetectTimeFormat

func DetectTimeFormat(in string) string

func GenericMarshalJSON

func GenericMarshalJSON(in interface{}, extraData ...map[string]interface{}) ([]byte, error)

func IsBoolean

func IsBoolean(inI interface{}) bool

func IsBooleanFalse

func IsBooleanFalse(inI interface{}) bool

func IsBooleanTrue

func IsBooleanTrue(inI interface{}) bool

func IsFloat

func IsFloat(in interface{}) bool

func IsHexadecimal added in v1.7.49

func IsHexadecimal(in interface{}) bool

func IsInteger

func IsInteger(in interface{}) bool

func IsKind

func IsKind(in interface{}, kinds ...reflect.Kind) bool

Dectect whether the concrete underlying value of the given input is one or more Kinds of value.

func IsNumeric

func IsNumeric(in interface{}) bool

func IsTime

func IsTime(inI interface{}) bool

func IsZero

func IsZero(value interface{}) bool

Returns whether the given value represents the underlying type's zero value

func JSONPath added in v1.9.3

func JSONPath(data interface{}, query string, autowrap bool) (interface{}, error)

Performs a JSONPath query against the given object and returns the results. JSONPath description, syntax, and examples are available at http://goessner.net/articles/JsonPath/.

func ParseDuration

func ParseDuration(in string) (time.Duration, error)

func RegisterTypeHandler added in v1.5.55

func RegisterTypeHandler(handler TypeConvertFunc, types ...string)

Register's a handler used for converting one type to another. Type are checked in the following manner: The input value's reflect.Type String() value is matched, falling back to its reflect.Kind String() value, finally checking for a special "*" value that matches any type. If the handler function returns nil, its value replaces the input value. If the special error type PassthroughType is returned, the original value is returned unmodified.

func ResolveValue

func ResolveValue(in interface{}) interface{}

func SliceEach

func SliceEach(slice interface{}, iterFn IterationFunc, preserve ...reflect.Kind) error

Iterate through each element of the given array, slice or channel; calling iterFn exactly once for each element. Otherwise, call iterFn one time with the given input as the argument.

func Sliceify added in v1.8.92

func Sliceify(in interface{}) []interface{}

Takes some input value and returns it as a slice.

func ToString

func ToString(in interface{}) (string, error)

Types

type ConvertType

type ConvertType int
const (
	Invalid ConvertType = iota
	Bytes
	String
	Float
	Integer
	Time
	Boolean
	Nil
	UserDefined
)

func Detect added in v1.7.49

func Detect(in interface{}) (ConvertType, interface{})

func DetectConvertType

func DetectConvertType(in interface{}) ConvertType

func (ConvertType) IsSupersetOf added in v1.7.20

func (self ConvertType) IsSupersetOf(other ConvertType) bool

func (ConvertType) String

func (self ConvertType) String() string

type IterationFunc

type IterationFunc func(i int, value interface{}) error

type TimedReadCloser added in v1.8.30

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

A TimedReadCloser wraps an io.ReadCloser, keeping track of how long actually reading from and closing the ReadCloser took, as well as how many bytes were read.

Measurement starts from the first call to Read(), and ends when Close() is called.

func NewTimedReadCloser added in v1.8.30

func NewTimedReadCloser(rc io.ReadCloser) *TimedReadCloser

func (*TimedReadCloser) BytesRead added in v1.8.30

func (self *TimedReadCloser) BytesRead() int64

func (*TimedReadCloser) Close added in v1.8.30

func (self *TimedReadCloser) Close() (err error)

func (*TimedReadCloser) CloseDuration added in v1.8.30

func (self *TimedReadCloser) CloseDuration() time.Duration

func (*TimedReadCloser) Duration added in v1.8.30

func (self *TimedReadCloser) Duration() time.Duration

func (*TimedReadCloser) LastReadAt added in v1.8.30

func (self *TimedReadCloser) LastReadAt() time.Time

Return the time of the last call to Read()

func (*TimedReadCloser) Read added in v1.8.30

func (self *TimedReadCloser) Read(b []byte) (int, error)

func (*TimedReadCloser) ReadDuration added in v1.8.30

func (self *TimedReadCloser) ReadDuration() time.Duration

Return a running duration of how long reading has been happening. Updated on every call to Read().

func (*TimedReadCloser) Reset added in v1.8.30

func (self *TimedReadCloser) Reset()

Reset the internal counters to zero. Useful after calling SetReadCloser().

func (*TimedReadCloser) SetReadCloser added in v1.8.30

func (self *TimedReadCloser) SetReadCloser(rc io.ReadCloser)

Set the underlying io.ReadCloser. Does not call Reset(), so multiple ReadClosers can be cumulitively tracked.

func (*TimedReadCloser) SinceLastRead added in v1.8.30

func (self *TimedReadCloser) SinceLastRead() time.Duration

Return the duration of time since the last Read() occurred.

func (*TimedReadCloser) StartedAt added in v1.8.30

func (self *TimedReadCloser) StartedAt() time.Time

Return the time of the first call to Read().

type TypeConvertFunc added in v1.5.55

type TypeConvertFunc func(in interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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