to

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Overview

Package cast provides easy and safe casting in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(i interface{}) bool

Bool casts an interface to a bool type.

func BoolE

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

BoolE casts an interface to a bool type.

func BoolSlice

func BoolSlice(i interface{}) []bool

BoolSlice casts an interface to a []bool type.

func BoolSliceE

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

BoolSliceE casts an interface to a []bool type.

func Duration

func Duration(i interface{}) time.Duration

Duration casts an interface to a time.Duration type.

func DurationE

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

DurationE 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 DurationSliceE

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

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

func Float32

func Float32(i interface{}) float32

Float32 casts an interface to a float32 type.

func Float32E

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

Float32E casts an interface to a float32 type.

func Float64

func Float64(i interface{}) float64

Float64 casts an interface to a float64 type.

func Float64E

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

Float64E 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 Int16E

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

Int16E casts an interface to an int16 type.

func Int32

func Int32(i interface{}) int32

Int32 casts an interface to an int32 type.

func Int32E

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

Int32E casts an interface to an int32 type.

func Int64

func Int64(i interface{}) int64

Int64 casts an interface to an int64 type.

func Int64E

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

Int64E casts an interface to an int64 type.

func Int8

func Int8(i interface{}) int8

Int8 casts an interface to an int8 type.

func Int8E

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

Int8E casts an interface to an int8 type.

func IntE

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

IntE casts an interface to an int type.

func IntSlice

func IntSlice(i interface{}) []int

IntSlice casts an interface to a []int type.

func IntSliceE

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

IntSliceE casts an interface to a []int type.

func String

func String(i interface{}) string

String casts an interface to a string type.

func StringE

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

StringE 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 StringMapBoolE

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

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

func StringMapE

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

StringMapE casts an interface to a map[string]interface{} 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 StringMapInt64E

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

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

func StringMapIntE

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

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

func StringMapString

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

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

func StringMapStringE

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

StringMapStringE 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 StringMapStringSliceE

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

StringMapStringSliceE 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 StringSliceE

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

StringSliceE 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 error 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 Time

func Time(i interface{}) time.Time

Time casts an interface to a time.Time type.

func TimeE

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

TimeE casts an interface to a time.Time type.

func TimeInDefaultLocation

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

func TimeInDefaultLocationE

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

TimeInDefaultLocationE 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 ToSlice

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

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

func ToSliceE

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

ToSliceE casts an interface to a []interface{} 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 Uint16E

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

Uint16E casts an interface to a uint16 type.

func Uint32

func Uint32(i interface{}) uint32

Uint32 casts an interface to a uint32 type.

func Uint32E

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

Uint32E casts an interface to a uint32 type.

func Uint64

func Uint64(i interface{}) uint64

Uint64 casts an interface to a uint64 type.

func Uint64E

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

Uint64E casts an interface to a uint64 type.

func Uint8

func Uint8(i interface{}) uint8

Uint8 casts an interface to a uint8 type.

func Uint8E

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

Uint8E casts an interface to a uint type.

func UintE

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

UintE casts an interface to a uint type.

Types

type Value

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

func V

func V(v any) *Value

func (*Value) Any

func (v *Value) Any() any

Any returns input value as any

func (*Value) Bool

func (v *Value) Bool() (i bool)

func (*Value) BoolE

func (v *Value) BoolE() (b bool, e error)

GetBool returns input value as bool

func (*Value) Float

func (v *Value) Float() (i float64)

func (*Value) Float32

func (v *Value) Float32() (i float32)

func (*Value) Float32E

func (v *Value) Float32E() (f float32, err error)

FloatE returns input value as float64

func (*Value) FloatE

func (v *Value) FloatE() (f float64, e error)

FloatE returns input value as float64

func (*Value) Int

func (v *Value) Int() int

Int returns input as an int

func (*Value) Int16

func (v *Value) Int16() (i int16)

func (*Value) Int16E

func (v *Value) Int16E() (i16 int16, e error)

GetInt16 returns input as an int16

func (*Value) Int32

func (v *Value) Int32() (i int32)

func (*Value) Int32E

func (v *Value) Int32E() (i32 int32, e error)

Int32E returns input as an int32

func (*Value) Int64

func (v *Value) Int64() (i int64)

func (*Value) Int64E

func (v *Value) Int64E() (i64 int64, e error)

Int64E returns input value as int64

func (*Value) Int8

func (v *Value) Int8() int8

func (*Value) Int8E

func (v *Value) Int8E() (i8 int8, e error)

Int8E return input as an int8

func (*Value) Int8s

func (v *Value) Int8s() (i Values[int8])

func (*Value) Int8sE

func (s *Value) Int8sE() (Values[int8], error)

func (*Value) IntE

func (v *Value) IntE() (i int, e error)

func (*Value) Ints

func (v *Value) Ints() (i []int)

func (*Value) IntsE

func (s *Value) IntsE() ([]int, error)

func (*Value) IsNil

func (s *Value) IsNil() bool

func (*Value) Split

func (v *Value) Split(sep string) Values[string]

func (*Value) String

func (v *Value) String() (s string)

String returns input value as float64

func (*Value) Uint16

func (v *Value) Uint16() (i uint16)

func (*Value) Uint16E

func (v *Value) Uint16E() (u16 uint16, e error)

Uint16E returns input as an uint16 and return error if has

func (*Value) Uint32

func (v *Value) Uint32() (i uint32)

func (*Value) Uint32E

func (v *Value) Uint32E() (u32 uint32, e error)

Uint32E returns input as an uint32

func (*Value) Uint64

func (v *Value) Uint64() (i uint64)

func (*Value) Uint64E

func (v *Value) Uint64E() (u64 uint64, e error)

Uint64E returns input value as uint64

func (*Value) Uint8

func (v *Value) Uint8() (i uint8)

GetUint8 return input as an uint8

func (*Value) Uint8E

func (v *Value) Uint8E() (u8 uint8, e error)

GetUint8 return input as an uint8

func (*Value) VInts

func (v *Value) VInts() (i Values[int])

type ValueM

type ValueM[K comparable, T any] map[K]T

func Vm

func Vm[K comparable, T any](v map[K]T) ValueM[K, T]

func (ValueM[K, T]) Int

func (v ValueM[K, T]) Int() (i map[K]int)

func (ValueM[K, T]) IntE

func (v ValueM[K, T]) IntE() (i map[K]int)

func (ValueM[K, T]) KInt

func (v ValueM[K, T]) KInt() (i map[int]T)

func (ValueM[K, T]) KVInt

func (v ValueM[K, T]) KVInt() (i map[int]int)

func (ValueM[K, T]) String

func (v ValueM[K, T]) String() (i map[K]string)

type Values

type Values[T any] []T

func Vs

func Vs[T any](v []T) Values[T]

func (Values[T]) First

func (v Values[T]) First() (val *Value)

func (Values[T]) Int

func (v Values[T]) Int() (i []int)

func (Values[T]) Int32

func (v Values[T]) Int32() (i []int32)

func (Values[T]) String

func (v Values[T]) String() (i []string)

Jump to

Keyboard shortcuts

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