utils

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BoolAssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	if b, ok := v.(bool); !ok {
		return reflect.Value{}, errors.New("interface is not a bool")
	} else {
		if isPtr {
			return reflect.ValueOf(&b), nil
		} else {
			return reflect.ValueOf(b), nil
		}
	}
}
View Source
var Cache = &cache{caches: make(map[string]*expirableContent)}
View Source
var DurationAssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	var d time.Duration
	var err error
	if f, ok := v.(float64); ok {
		d = time.Duration(int64(f))
	} else if i, ok := v.(int64); ok {
		d = time.Duration(i)
	} else if s, ok := v.(string); ok {
		d, err = time.ParseDuration(s)
		if err != nil {
			return reflect.Value{}, err
		}
	} else {
		return reflect.Value{}, errors.New("interface is not a duration")
	}

	if isPtr {
		return reflect.ValueOf(&d), nil
	} else {
		return reflect.ValueOf(d), nil
	}
}
View Source
var Float64AssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	if f, ok := v.(float64); !ok {
		return reflect.Value{}, errors.New("interface is not a float64")
	} else {
		if isPtr {
			return reflect.ValueOf(&f), nil
		} else {
			return reflect.ValueOf(f), nil
		}
	}
}
View Source
var Int64AssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	if i, ok := v.(int64); !ok {
		if f, ok := v.(float64); !ok {
			return reflect.Value{}, errors.New("interface is not an int64")
		} else {
			if isPtr {
				pf := int64(f)
				return reflect.ValueOf(&pf), nil
			} else {
				return reflect.ValueOf(int64(f)), nil
			}
		}
	} else {
		if isPtr {
			return reflect.ValueOf(&i), nil
		} else {
			return reflect.ValueOf(i), nil
		}
	}
}
View Source
var IntAssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	if i, ok := v.(int); !ok {
		if f, ok := v.(float64); !ok {
			return reflect.Value{}, errors.New("interface is not an int")
		} else {
			if isPtr {
				pf := int(f)
				return reflect.ValueOf(&pf), nil
			} else {
				return reflect.ValueOf(int(f)), nil
			}
		}
	} else {
		if isPtr {
			return reflect.ValueOf(&i), nil
		} else {
			return reflect.ValueOf(i), nil
		}
	}
}
View Source
var JSONDurationAssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	var _d time.Duration
	var err error
	if f, ok := v.(float64); ok {
		_d = time.Duration(int64(f))
	} else if i, ok := v.(int64); ok {
		_d = time.Duration(i)
	} else if s, ok := v.(string); ok {
		_d, err = time.ParseDuration(s)
		if err != nil {
			return reflect.Value{}, err
		}
	} else {
		return reflect.Value{}, errors.New("interface is not a duration")
	}

	d := JSONDuration{Duration: _d}
	if isPtr {
		return reflect.ValueOf(&d), nil
	} else {
		return reflect.ValueOf(d), nil
	}
}
View Source
var Render *render.Render
View Source
var StringAssignReader = func(v interface{}, isPtr bool) (reflect.Value, error) {
	if s, ok := v.(string); !ok {
		return reflect.Value{}, errors.New("interface is not a string")
	} else {
		if isPtr {
			return reflect.ValueOf(&s), nil
		} else {
			return reflect.ValueOf(s), nil
		}
	}
}
View Source
var TagName = "assign"

Functions

func AlphaNumeric

func AlphaNumeric(s string) bool

func Assign

func Assign(d interface{}, s map[string]interface{}, rds map[string]AssignReader) error

func FatalIfErr

func FatalIfErr(err error)

func ForceAssign

func ForceAssign(d interface{}, s map[string]interface{}, rds map[string]AssignReader) error

func MilliSecToNano

func MilliSecToNano(milli int64) int64

func MilliSecToSec

func MilliSecToSec(milli int64) int64

func NanoToMilli

func NanoToMilli(nano int64) int64

func QueryToMap

func QueryToMap(values url.Values) map[string]string

func StringSliceContains

func StringSliceContains(s []string, v string) bool

func ToStringMap

func ToStringMap(m map[interface{}]interface{}) (map[string]interface{}, error)

Types

type AssignReader

type AssignReader func(interface{}, bool) (reflect.Value, error)

type AtomBool

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

func (*AtomBool) Get

func (b *AtomBool) Get() bool

func (*AtomBool) Set

func (b *AtomBool) Set(value bool)

type JSONDuration

type JSONDuration struct {
	time.Duration
}

func (*JSONDuration) MarshalJSON

func (d *JSONDuration) MarshalJSON() ([]byte, error)

func (*JSONDuration) UnmarshalJSON

func (d *JSONDuration) UnmarshalJSON(data []byte) error

type MarshallableErrors

type MarshallableErrors map[string]error

func (MarshallableErrors) MarshalJSON

func (m MarshallableErrors) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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