gconv

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// StructTagPriority defines the default priority tags for Map*/Struct* functions.
	// Note, the "gconv", "param", "params" tags are used by old version of package.
	// It is strongly recommended using short tag "c" or "p" instead in the future.
	StructTagPriority = []string{"gconv", "param", "params", "c", "p", "json"}
)

Functions

func Bool

func Bool(i interface{}) bool

Bool casts an interface to a bool type.

func BoolSlice

func BoolSlice(i interface{}) []bool

BoolSlice casts an interface to a []bool type.

func Byte

func Byte(any interface{}) byte

Byte converts `any` to byte.

func Bytes

func Bytes(any interface{}) []byte

Bytes converts `any` to []byte.

func Duration

func Duration(i interface{}) time.Duration

Duration casts an interface to a time.Duration type.

func DurationSlice

func DurationSlice(i interface{}) []time.Duration

DurationSlice casts an interface to a []time.Duration type.

func Float32

func Float32(i interface{}) float32

Float32 casts an interface to a float32 type.

func Float64

func Float64(i interface{}) float64

Float64 casts an interface to a float64 type.

func Int

func Int(i interface{}) int

Int casts an interface to an int type.

func Int16

func Int16(i interface{}) int16

Int16 casts an interface to an int16 type.

func Int32

func Int32(i interface{}) int32

Int32 casts an interface to an int32 type.

func Int32ToString

func Int32ToString(i int32) string

Int32ToString casts an interface to a string type.

func Int32s

func Int32s(any interface{}) []int32

Int32s converts `any` to []int32.

func Int64

func Int64(i interface{}) int64

Int64 casts an interface to an int64 type.

func Int64s

func Int64s(any interface{}) []int64

Int64s converts `any` to []int64.

func Int8

func Int8(i interface{}) int8

Int8 casts an interface to an int8 type.

func IntSlice

func IntSlice(i interface{}) []int

IntSlice casts an interface to a []int type.

func IntToString

func IntToString(i int) string

IntToString casts an interface to a string type.

func Interfaces

func Interfaces(any interface{}) []interface{}

Interfaces converts `any` to []interface{}.

func Ints

func Ints(any interface{}) []int

Ints converts `any` to []int.

func Map

func Map(value interface{}, tags ...string) map[string]interface{}

Map converts any variable `value` to map[string]interface{}. If the parameter `value` is not a map/struct/*struct type, then the conversion will fail and returns nil.

If `value` is a struct/*struct object, the second parameter `tags` specifies the most priority tags that will be detected, otherwise it detects the tags in order of: gconv, json, field name.

func MapStrStr

func MapStrStr(value interface{}, tags ...string) map[string]string

MapStrStr converts `value` to map[string]string. Note that there might be data copy for this map type converting.

func Rune

func Rune(any interface{}) rune

Rune converts `any` to rune.

func Slice

func Slice(i interface{}) []interface{}

Slice casts an interface to a []interface{} type.

func SliceAny

func SliceAny(any interface{}) []interface{}

SliceAny is alias of Interfaces.

func SliceInt

func SliceInt(any interface{}) []int

SliceInt is alias of Ints.

func SliceInt32

func SliceInt32(any interface{}) []int32

SliceInt32 is alias of Int32s.

func SliceInt64

func SliceInt64(any interface{}) []int64

SliceInt is alias of Int64s.

func SliceStr

func SliceStr(any interface{}) []string

SliceStr is alias of Strings.

func String

func String(i interface{}) string

String casts an interface to a string type.

func StringMap

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

StringMap casts an interface to a map[string]interface{} type.

func StringMapBool

func StringMapBool(i interface{}) map[string]bool

StringMapBool casts an interface to a map[string]bool type.

func StringMapInt

func StringMapInt(i interface{}) map[string]int

StringMapInt casts an interface to a map[string]int type.

func StringMapInt64

func StringMapInt64(i interface{}) map[string]int64

StringMapInt64 casts an interface to a map[string]int64 type.

func StringMapString

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

StringMapString casts an interface to a map[string]string type.

func StringMapStringSlice

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

StringMapStringSlice casts an interface to a map[string][]string type.

func StringSlice

func StringSlice(i interface{}) []string

StringSlice casts an interface to a []string type.

func StringToDate

func StringToDate(s string) (time.Time, error)

StringToDate attempts to parse a string into a time.Time type using a predefined list of formats. If no suitable format is found, an errors is returned.

func StringToDateInDefaultLocation

func StringToDateInDefaultLocation(s string, location *time.Location) (time.Time, error)

StringToDateInDefaultLocation casts an empty interface to a time.Time, interpreting inputs without a timezone to be in the given location, or the local timezone if nil.

func Strings

func Strings(any interface{}) []string

Strings converts `any` to []string.

func Time

func Time(i interface{}) time.Time

Time casts an interface to a time.Time type.

func TimeInDefaultLocation

func TimeInDefaultLocation(i interface{}, location *time.Location) time.Time

func ToBoolE

func ToBoolE(i interface{}) (bool, error)

ToBoolE casts an interface to a bool type.

func ToBoolSliceE

func ToBoolSliceE(i interface{}) ([]bool, error)

ToBoolSliceE casts an interface to a []bool type.

func ToDurationE

func ToDurationE(i interface{}) (d time.Duration, err error)

ToDurationE casts an interface to a time.Duration type.

func ToDurationSliceE

func ToDurationSliceE(i interface{}) ([]time.Duration, error)

ToDurationSliceE casts an interface to a []time.Duration type.

func ToFloat32E

func ToFloat32E(i interface{}) (float32, error)

ToFloat32E casts an interface to a float32 type.

func ToFloat64E

func ToFloat64E(i interface{}) (float64, error)

ToFloat64E casts an interface to a float64 type.

func ToInt16E

func ToInt16E(i interface{}) (int16, error)

ToInt16E casts an interface to an int16 type.

func ToInt32E

func ToInt32E(i interface{}) (int32, error)

ToInt32E casts an interface to an int32 type.

func ToInt64E

func ToInt64E(i interface{}) (int64, error)

ToInt64E casts an interface to an int64 type.

func ToInt8E

func ToInt8E(i interface{}) (int8, error)

ToInt8E casts an interface to an int8 type.

func ToIntE

func ToIntE(i interface{}) (int, error)

ToIntE casts an interface to an int type.

func ToIntSliceE

func ToIntSliceE(i interface{}) ([]int, error)

ToIntSliceE casts an interface to a []int type.

func ToSliceE

func ToSliceE(i interface{}) ([]interface{}, error)

ToSliceE casts an interface to a []interface{} type.

func ToStringE

func ToStringE(i interface{}) (string, error)

ToStringE casts an interface to a string type.

func ToStringMapBoolE

func ToStringMapBoolE(i interface{}) (map[string]bool, error)

ToStringMapBoolE casts an interface to a map[string]bool type.

func ToStringMapE

func ToStringMapE(i interface{}) (map[string]interface{}, error)

ToStringMapE casts an interface to a map[string]interface{} type.

func ToStringMapInt64E

func ToStringMapInt64E(i interface{}) (map[string]int64, error)

ToStringMapInt64E casts an interface to a map[string]int64{} type.

func ToStringMapIntE

func ToStringMapIntE(i interface{}) (map[string]int, error)

ToStringMapIntE casts an interface to a map[string]int{} type.

func ToStringMapStringE

func ToStringMapStringE(i interface{}) (map[string]string, error)

ToStringMapStringE casts an interface to a map[string]string type.

func ToStringMapStringSliceE

func ToStringMapStringSliceE(i interface{}) (map[string][]string, error)

ToStringMapStringSliceE casts an interface to a map[string][]string type.

func ToStringSliceE

func ToStringSliceE(i interface{}) ([]string, error)

ToStringSliceE casts an interface to a []string type.

func ToTimeE

func ToTimeE(i interface{}) (tim time.Time, err error)

ToTimeE casts an interface to a time.Time type.

func ToTimeInDefaultLocationE

func ToTimeInDefaultLocationE(i interface{}, location *time.Location) (tim time.Time, err error)

ToTimeInDefaultLocationE casts an empty interface to time.Time, interpreting inputs without a timezone to be in the given location, or the local timezone if nil.

func ToUint16E

func ToUint16E(i interface{}) (uint16, error)

ToUint16E casts an interface to a uint16 type.

func ToUint32E

func ToUint32E(i interface{}) (uint32, error)

ToUint32E casts an interface to a uint32 type.

func ToUint64E

func ToUint64E(i interface{}) (uint64, error)

ToUint64E casts an interface to a uint64 type.

func ToUint8E

func ToUint8E(i interface{}) (uint8, error)

ToUint8E casts an interface to a uint type.

func ToUintE

func ToUintE(i interface{}) (uint, error)

ToUintE casts an interface to a uint type.

func Uint

func Uint(i interface{}) uint

Uint casts an interface to a uint type.

func Uint16

func Uint16(i interface{}) uint16

Uint16 casts an interface to a uint16 type.

func Uint32

func Uint32(i interface{}) uint32

Uint32 casts an interface to a uint32 type.

func Uint64

func Uint64(i interface{}) uint64

Uint64 casts an interface to a uint64 type.

func Uint8

func Uint8(i interface{}) uint8

Uint8 casts an interface to a uint8 type.

func UnsafeBytesToStr

func UnsafeBytesToStr(b []byte) string

UnsafeBytesToStr converts []byte to string without memory copy. Note that, if you completely sure you will never use `b` variable in the feature, you can use this unsafe function to implement type conversion in high performance.

func UnsafeStrToBytes

func UnsafeStrToBytes(s string) []byte

UnsafeStrToBytes converts string to []byte without memory copy. Note that, if you completely sure you will never use `s` variable in the feature, you can use this unsafe function to implement type conversion in high performance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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