Documentation
¶
Overview ¶
Package to is a helper package for converting between datatypes.
If a certain value can not be directly converted to another, the zero value of the destination type is returned instead.
Index ¶
- Constants
- func AsBool(v interface{}) bool
- func AsDuration(v interface{}) time.Duration
- func AsFloat(v interface{}) float64
- func AsInt(v interface{}) int
- func AsInt64(v interface{}) int64
- func AsMap(v interface{}) map[string]interface{}
- func AsSlice(v interface{}, val []interface{}) []interface{}
- func AsString(v interface{}) string
- func AsTime(v interface{}) time.Time
- func Bool(value interface{}) (bool, error)
- func Bytes(val interface{}) []byte
- func Convert(value interface{}, t reflect.Kind) (interface{}, error)
- func Duration(val interface{}) (time.Duration, error)
- func Float64(val interface{}) (float64, error)
- func Int64(val interface{}) (int64, error)
- func Map(val interface{}) (map[string]interface{}, error)
- func MustBool(v interface{}) bool
- func MustDuration(v interface{}) time.Duration
- func MustFloat(v interface{}) float64
- func MustInt(v interface{}) int
- func MustInt64(v interface{}) int64
- func MustMap(v interface{}, val map[string]interface{}) map[string]interface{}
- func MustSlice(v interface{}, val []interface{}) []interface{}
- func MustString(v interface{}) string
- func MustTime(v interface{}) time.Time
- func OrBool(v interface{}, val bool) bool
- func OrDuration(v interface{}, val time.Duration) time.Duration
- func OrFloat(v interface{}, val float64) float64
- func OrInt(v interface{}, val int) int
- func OrInt64(v interface{}, val int64) int64
- func OrMap(v interface{}, val map[string]interface{}) map[string]interface{}
- func OrSlice(v interface{}, val []interface{}) []interface{}
- func OrString(v interface{}) string
- func OrTime(v interface{}, val time.Time) time.Time
- func Slice(val interface{}) ([]interface{}, error)
- func String(val interface{}) string
- func Time(val interface{}) (time.Time, error)
- func Uint64(val interface{}) (uint64, error)
- func ZeroBool(v interface{}) bool
- func ZeroDuration(v interface{}) time.Duration
- func ZeroFloat(v interface{}) float64
- func ZeroInt(v interface{}) int
- func ZeroInt64(v interface{}) int64
- func ZeroMap(v interface{}) map[string]interface{}
- func ZeroSlice(v interface{}, val []interface{}) []interface{}
- func ZeroString(v interface{}) string
- func ZeroTime(v interface{}) time.Time
Constants ¶
const ( // KindTime is reserved for Time kind. KindTime reflect.Kind = iota + 1000000000 // KindDuration is reserved for Duration kind. KindDuration )
Variables ¶
This section is empty.
Functions ¶
func AsDuration ¶
AsDuration converts v to Duration or returns Duration(0).
func AsFloat ¶
func AsFloat(v interface{}) float64
AsFloat converts v to float64 or returns float64(0)
func AsMap ¶
func AsMap(v interface{}) map[string]interface{}
AsMap converts v to map[string]interface{} or returns val.
func AsSlice ¶
func AsSlice(v interface{}, val []interface{}) []interface{}
AsSlice converts v to []interface{} or returns val.
func Bytes ¶
func Bytes(val interface{}) []byte
Bytes tries to convert the argument into a []byte array. Returns []byte{} if any error occurs.
func Duration ¶
Duration tries to convert the argument into a time.Duration value. Returns time.Duration(0) if any error occurs.
func Float64 ¶
Float64 tries to convert the argument into a float64. Returns float64(0.0) if any error occurs.
func Int64 ¶
Int64 tries to convert the argument into an int64. Returns int64(0) if any error occurs.
func MustDuration ¶
MustDuration converts v to Duration or panics.
func MustSlice ¶
func MustSlice(v interface{}, val []interface{}) []interface{}
MustSlice converts v to []interface{} or returns val.
func OrDuration ¶
OrDuration converts v to Duration or returns val.
func OrSlice ¶
func OrSlice(v interface{}, val []interface{}) []interface{}
OrSlice converts v to []interface{} or returns val.
func String ¶
func String(val interface{}) string
String tries to convert the argument into a string. Returns "" if any error occurs.
func Uint64 ¶
Uint64 tries to convert the argument into an uint64. Returns uint64(0) if any error occurs.
func ZeroDuration ¶
ZeroDuration converts v to Duration or returns Duration(0).
func ZeroFloat ¶
func ZeroFloat(v interface{}) float64
ZeroFloat converts v to float64 or returns float64(0)
func ZeroMap ¶
func ZeroMap(v interface{}) map[string]interface{}
ZeroMap converts v to map[string]interface{} or returns val.
func ZeroSlice ¶
func ZeroSlice(v interface{}, val []interface{}) []interface{}
ZeroSlice converts v to []interface{} or returns val.
func ZeroString ¶
func ZeroString(v interface{}) string
ZeroString converts v to string or returns ""
Types ¶
This section is empty.
