utils

package
v0.0.0-...-776d397 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 16 Imported by: 3

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

func Bool(s bool) *bool

Bool returns the input value's pointer.

func BoolR

func BoolR(s *bool) bool

BoolR is the reverse to Bool.

func Cause

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

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

func Float32(s float32) *float32

Float32 returns the input value's pointer.

func Float32R

func Float32R(s *float32) float32

Float32R is the reverse to Float32.

func Float64

func Float64(s float64) *float64

Float64 returns the input value's pointer.

func Float64R

func Float64R(s *float64) float64

Float64R is the reverse to Float64.

func GetFloat32

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

GetFloat32 returns a float32 for a given key in values.

func GetFloat32Default

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

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

GetFloat64 returns a float64 for a given key in values.

func GetFloat64Default

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

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

GetInt returns an int for a given key in values.

func GetInt32

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

GetInt32 returns an int32 for a given key in values.

func GetInt32Default

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

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

GetInt64 returns an int64 for a given key in values.

func GetInt64Default

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

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

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

GetString returns a string for a given key in values.

func GetStringDefault

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

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

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

func GetStringSliceDefault

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

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

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

func GetenvDefault

func GetenvDefault(key string, def string) string

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

func HelpMessage

func HelpMessage() string

HelpMessage returns a string explaining how profiling works.

func Int

func Int(s int) *int

Int returns the input value's pointer.

func Int32

func Int32(s int32) *int32

Int32 returns the input value's pointer.

func Int32R

func Int32R(s *int32) int32

Int32R is the reverse to Int32.

func Int64

func Int64(s int64) *int64

Int64 returns the input value's pointer.

func Int64R

func Int64R(s *int64) int64

Int64R is the reverse to Int64.

func IntNullCheck

func IntNullCheck(value int) bool

func IntR

func IntR(s *int) int

IntR is the reverse to Int.

func IsLocalIP

func IsLocalIP(ip string) bool

func KeyStringToInterface

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

func Profile() interface {
	Stop()
}

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

func String

func String(s string) *string

String returns the input value's pointer.

func StringNullCheck

func StringNullCheck(value string) bool

func StringR

func StringR(s *string) string

StringR is the reverse to String.

func ToJSONMap

func ToJSONMap(i interface{}) interface{}

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

Types

type DebugCarrier

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

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

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

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

type StackTracer interface {
	StackTrace() errors.StackTrace
}

type StatusCarrier

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

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