utils

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyCanNotBeTypeAsserted = errors.New("key could not be type asserted")

ErrKeyCanNotBeTypeAsserted is returned when the key can not be type asserted.

View Source
var ErrKeyDoesNotExist = errors.New("key is not present in map")

ErrKeyDoesNotExist is returned when the key does not exist in the map.

Functions

func AppendMapIfExists

func AppendMapIfExists(condition bool, des map[string]interface{}, key string, value interface{})

func Bool added in v0.3.0

func Bool(s bool) *bool

Bool returns the input value's pointer.

func BoolR added in v0.3.0

func BoolR(s *bool) bool

BoolR is the reverse to Bool.

func Cause added in v0.3.0

func Cause(err error) error

Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:

type causer interface {
       Cause() error
}

If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.

func Contains

func Contains(s []interface{}, e interface{}) bool

func ConvertBool

func ConvertBool(value string) bool

func ConvertInt

func ConvertInt(value string) int

func ConvertInt32

func ConvertInt32(value string) int32

func ConvertUint8

func ConvertUint8(value string) uint8

func Delete

func Delete(slice []string, place int) []string

func EqualAsJSON added in v0.3.0

func EqualAsJSON(t *testing.T, expected, actual interface{}, args ...interface{})

func ErrorFatal

func ErrorFatal(err error)

func ErrorWrap

func ErrorWrap(err error, wrap string) error

func Find

func Find(slice []string, val string) (int, bool)

func Float32 added in v0.3.0

func Float32(s float32) *float32

Float32 returns the input value's pointer.

func Float32R added in v0.3.0

func Float32R(s *float32) float32

Float32R is the reverse to Float32.

func Float64 added in v0.3.0

func Float64(s float64) *float64

Float64 returns the input value's pointer.

func Float64R added in v0.3.0

func Float64R(s *float64) float64

Float64R is the reverse to Float64.

func GetFloat32 added in v0.3.0

func GetFloat32(values map[interface{}]interface{}, key interface{}) (float32, error)

GetFloat32 returns a float32 for a given key in values.

func GetFloat32Default added in v0.3.0

func GetFloat32Default(values map[interface{}]interface{}, key interface{}, defaultValue float32) float32

GetFloat32Default returns a float32 or the default value for a given key in values.

func GetFloat64 added in v0.3.0

func GetFloat64(values map[interface{}]interface{}, key interface{}) (float64, error)

GetFloat64 returns a float64 for a given key in values.

func GetFloat64Default added in v0.3.0

func GetFloat64Default(values map[interface{}]interface{}, key interface{}, defaultValue float64) float64

GetFloat64Default returns a float64 or the default value for a given key in values.

func GetInt added in v0.3.0

func GetInt(values map[interface{}]interface{}, key interface{}) (int, error)

GetInt returns an int for a given key in values.

func GetInt32 added in v0.3.0

func GetInt32(values map[interface{}]interface{}, key interface{}) (int32, error)

GetInt32 returns an int32 for a given key in values.

func GetInt32Default added in v0.3.0

func GetInt32Default(values map[interface{}]interface{}, key interface{}, defaultValue int32) int32

GetInt32Default returns a int32 or the default value for a given key in values.

func GetInt64 added in v0.3.0

func GetInt64(values map[interface{}]interface{}, key interface{}) (int64, error)

GetInt64 returns an int64 for a given key in values.

func GetInt64Default added in v0.3.0

func GetInt64Default(values map[interface{}]interface{}, key interface{}, defaultValue int64) int64

GetInt64Default returns a int64 or the default value for a given key in values.

func GetIntDefault added in v0.3.0

func GetIntDefault(values map[interface{}]interface{}, key interface{}, defaultValue int) int

GetIntDefault returns a int or the default value for a given key in values.

func GetInterfaceIP

func GetInterfaceIP() string

func GetString added in v0.3.0

func GetString(values map[interface{}]interface{}, key interface{}) (string, error)

GetString returns a string for a given key in values.

func GetStringDefault added in v0.3.0

func GetStringDefault(values map[interface{}]interface{}, key interface{}, defaultValue string) string

GetStringDefault returns a string or the default value for a given key in values.

func GetStringSlice added in v0.3.0

func GetStringSlice(values map[interface{}]interface{}, key interface{}) ([]string, error)

GetStringSlice returns a string slice for a given key in values.

func GetStringSliceDefault added in v0.3.0

func GetStringSliceDefault(values map[interface{}]interface{}, key interface{}, defaultValue []string) []string

GetStringSliceDefault returns a string slice or the default value for a given key in values.

func GetTime added in v0.3.0

func GetTime(values map[interface{}]interface{}, key interface{}) (time.Time, error)

GetTime returns a string slice for a given key in values.

func GetenvDefault added in v0.3.0

func GetenvDefault(key string, def string) string

GetenvDefault returns an environment variable or the default value if it is empty.

func HelpMessage added in v0.3.0

func HelpMessage() string

HelpMessage returns a string explaining how profiling works.

func Int added in v0.3.0

func Int(s int) *int

Int returns the input value's pointer.

func Int32 added in v0.3.0

func Int32(s int32) *int32

Int32 returns the input value's pointer.

func Int32R added in v0.3.0

func Int32R(s *int32) int32

Int32R is the reverse to Int32.

func Int64 added in v0.3.0

func Int64(s int64) *int64

Int64 returns the input value's pointer.

func Int64R added in v0.3.0

func Int64R(s *int64) int64

Int64R is the reverse to Int64.

func IntNullCheck

func IntNullCheck(value int) bool

func IntR added in v0.3.0

func IntR(s *int) int

IntR is the reverse to Int.

func IsLocalIP

func IsLocalIP(ip string) bool

func KeyStringToInterface added in v0.3.0

func KeyStringToInterface(i map[string]interface{}) map[interface{}]interface{}

KeyStringToInterface converts map[string]interface{} to map[interface{}]interface{}

func MapToStruct

func MapToStruct(to interface{}, tag string, from interface{}) error

func Profile added in v0.3.0

func Profile() interface {
	Stop()
}

Profile parses the PROFILING environment variable and executes the proper profiling task.

func String added in v0.3.0

func String(s string) *string

String returns the input value's pointer.

func StringNullCheck

func StringNullCheck(value string) bool

func StringR added in v0.3.0

func StringR(s *string) string

StringR is the reverse to String.

func ToJSONMap added in v0.3.0

func ToJSONMap(i interface{}) interface{}

ToJSONMap converts all map[interface{}]interface{} occurrences (nested as well) to map[string]interface{}.

Types

type DebugCarrier added in v0.3.0

type DebugCarrier interface {
	// Debug returns debugging information for the error, if applicable.
	Debug() string
}

DebugCarrier can be implemented by an error to support error contexts.

type DetailsCarrier added in v0.3.0

type DetailsCarrier interface {
	// Details returns details on the error, if applicable.
	Details() map[string]interface{}
}

DetailsCarrier can be implemented by an error to support error contexts.

type Error

type Error struct {
	Code   int
	Reason string
}

Error .

type Future

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

Future .

func NewFuture

func NewFuture() *Future

NewFuture .

func (*Future) Await

func (future *Future) Await() (map[string]interface{}, *Error)

Await .

func (*Future) Reject

func (future *Future) Reject(err *Error)

Reject .

func (*Future) Resolve

func (future *Future) Resolve(result map[string]interface{})

Resolve .

func (*Future) Then

func (future *Future) Then(resolve func(result map[string]interface{}), reject func(err *Error))

Then .

type ReasonCarrier added in v0.3.0

type ReasonCarrier interface {
	// Reason returns the reason for the error, if applicable.
	Reason() string
}

ReasonCarrier can be implemented by an error to support error contexts.

type RequestIDCarrier added in v0.3.0

type RequestIDCarrier interface {
	// RequestID returns the ID of the request that caused the error, if applicable.
	RequestID() string
}

RequestIDCarrier can be implemented by an error to support error contexts.

type StackTracer added in v0.3.0

type StackTracer interface {
	StackTrace() errors.StackTrace
}

type StatusCarrier added in v0.3.0

type StatusCarrier interface {
	// ID returns the error id, if applicable.
	Status() string
}

StatusCarrier can be implemented by an error to support error contexts.

type StatusCodeCarrier added in v0.3.0

type StatusCodeCarrier interface {
	// StatusCode returns the status code of this error.
	StatusCode() int
}

StatusCodeCarrier can be implemented by an error to support setting status codes in the error itself.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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