convert

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 19 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 that, the `gconv/param` tags are used by old version of package.
	// It is strongly recommended using short tag `c/p` instead in the future.
	StructTagPriority = tag.StructTagPriority
)

Functions

func Any

func Any(value interface{}) *any

func Bool

func Bool(any interface{}) bool

Bool converts `any` to bool. It returns false if `any` is: false, "", 0, "false", "off", "no", empty slice/map.

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 added in v0.0.7

func Duration(any interface{}) time.Duration

func Float32

func Float32(any interface{}) float32

Float32 converts `any` to float32.

func Float64

func Float64(any interface{}) float64

Float64 converts `any` to float64.

func FormEncode added in v0.0.4

func FormEncode(params map[string]interface{}) url.Values

func Int

func Int(any interface{}) int

Int converts `any` to int.

func Int16

func Int16(any interface{}) int16

Int16 converts `any` to int16.

func Int32

func Int32(any interface{}) int32

Int32 converts `any` to int32.

func Int32s

func Int32s(any interface{}) []int32

Int32s converts `any` to []int32.

func Int64

func Int64(any interface{}) int64

Int64 converts `any` to int64.

func Int64s

func Int64s(any interface{}) []int64

Int64s converts `any` to []int64.

func Int8

func Int8(any interface{}) int8

Int8 converts `any` to int8.

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{}

func ParseDuration added in v0.0.7

func ParseDuration(s string) (duration time.Duration, err error)

func Rune

func Rune(any interface{}) rune

Rune converts `any` to rune.

func Runes

func Runes(any interface{}) []rune

Runes converts `any` to []rune.

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

SliceInt64 is alias of Int64s.

func SliceStr

func SliceStr(any interface{}) []string

SliceStr is alias of Strings.

func String

func String(any interface{}) string

String 将任意类型转换为字符串

func Strings

func Strings(any interface{}) []string

Strings converts `any` to []string.

func StructMap added in v0.0.3

func StructMap(value interface{}, option ...MapOption) 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 Time

func Time(any interface{}, format ...string) time.Time

Time converts `any` to time.Time.

func Uint

func Uint(any interface{}) uint

Uint 将任意类型转换为 uint

func Uint16

func Uint16(any interface{}) uint16

Uint16 将任意类型转换为 uint16,超过 65535 的值会被截断为 65535

func Uint32

func Uint32(any interface{}) uint32

Uint32 将任意类型转换为 uint32,超过 4294967295 的值会被截断为 4294967295

func Uint64

func Uint64(any interface{}) uint64

Uint64 将任意类型转换为 uint64

func Uint8

func Uint8(any interface{}) uint8

Uint8 将任意类型转换为 uint8,超过 255 的值会被截断为 255

Types

type MapOption added in v0.0.3

type MapOption struct {
	// Deep marks doing Map function recursively, which means if the attribute of given converting value
	// is also a struct/*struct, it automatically calls Map function on this attribute converting it to
	// a map[string]interface{} type variable.
	Deep bool

	// OmitEmpty ignores the attributes that has json `omitempty` tag.
	OmitEmpty bool

	// Tags specifies the converted map key name by struct tag name.
	Tags []string
}

MapOption specifies the option for map converting.

Jump to

Keyboard shortcuts

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