value

package module
v0.0.0-...-c4c3f18 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 9 Imported by: 6

README

Value: converting any value type to another any value type

Example:

var x int = 25
valueX := value.New(x)
stringX := valueX.String()

Available operations with value

func (v Value) IsNil() bool 

// IsEmpty ...
func (v Value) IsEmpty() bool 

// Interface ...
func (v Value) Interface(defaultValue ...interface{}) interface{} 

// String ...
func (v Value) String(defaultValue ...string) string 

// Bool ...
func (v Value) Bool(boolTrue ...string) bool 

// Float64 ...
func (v Value) Float64(defaultValue ...float64) float64 

// Float32 ...
func (v Value) Float32(defaultValue ...float32) float32

// Int64 ...
func (v Value) Int64(defaultValue ...int64) int64 

// Int32 ...
func (v Value) Int32(defaultValue ...int32) int32 

// Int16 ...
func (v Value) Int16(defaultValue ...int16) int16

// Int8 ...
func (v Value) Int8(defaultValue ...int8) int8 

// Int ...
func (v Value) Int(defaultValue ...int) int 

// Uint64 ...
func (v Value) Uint64(defaultValue ...uint64) uint64

// Uint32 ...
func (v Value) Uint32(defaultValue ...uint32) uint32 

// Uint16 ...
func (v Value) Uint16(defaultValue ...uint16) uint16

// Uint8 ...
func (v Value) Uint8(defaultValue ...uint8) uint8 

// Uint ...
func (v Value) Uint(defaultValue ...uint) uint 

// Time ...
func (v Value) Time(timeFormat ...string) time.Time 

// TimeString. timeFormat[0] : format of time string, timeFormat[1] : if interface string optionly provide specific format
func (v Value) TimeString(timeFormat ...string) string 

// StringSlice ...
func (v Value) StringSlice(seperator ...string) []string 

// Map ...
func (v Value) Map() map[string]interface{} 

// MapSlice ...
func (v Value) MapSlice() []map[string]interface{} 

// MapGet ...
func (v Value) MapGet(path string) Value 

// Slice ...
func (v Value) Slice(seperator ...string) []interface{} 

// IntSlice ...
func (v Value) IntSlice(seperator ...string) []int 

// BoolSlice ...
// boolTrueAndSeperator 1: boolTrue, 2:seperator, empty string "" to skip parameter
func (v Value) BoolSlice(boolTrueAndSeperator ...string) []bool 

// TimeSlice ...
// timeFormatAndSeperator 1: timeFormat, 2:seperator, empty string "" to skip parameter
func (v Value) TimeSlice(timeFormatAndSeperator ...string) []time.Time 

// ValueMap ...
func (v Value) ValueMap() map[string]Value 

// ValueSlice ...
func (v Value) ValueSlice(seperator ...string) []Value 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringToDate

func StringToDate(s string, timeFormat ...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 ToBool

func ToBool(i interface{}, boolTrue ...string) bool

func ToBoolE

func ToBoolE(i interface{}, boolTrue ...string) (value bool, err error)

ToBoolE casts an interface to a bool type.

func ToBoolSlice

func ToBoolSlice(i interface{}, boolTrueAndSeperator ...string) []bool

func ToBoolSliceE

func ToBoolSliceE(i interface{}, boolTrueAndSeperator ...string) (value []bool, err error)

ToBoolSliceE casts an interface to a []bool type. boolTrueAndSeperator 1: boolTrue, 2:seperator, empty string "" to skip parameter

func ToFloat32

func ToFloat32(i interface{}, defaultValue ...float32) float32

func ToFloat32E

func ToFloat32E(i interface{}, defaultValue ...float32) (value float32, err error)

ToFloat32E casts an interface to a float32 type.

func ToFloat64

func ToFloat64(i interface{}, defaultValue ...float64) float64

func ToFloat64E

func ToFloat64E(i interface{}, defaultValue ...float64) (value float64, err error)

ToFloat64E casts an interface to a float64 type.

func ToInt

func ToInt(i interface{}, defaultValue ...int) int

func ToInt16

func ToInt16(i interface{}, defaultValue ...int16) int16

func ToInt16E

func ToInt16E(i interface{}, defaultValue ...int16) (value int16, err error)

ToInt16E casts an interface to an int16 type.

func ToInt32

func ToInt32(i interface{}, defaultValue ...int32) int32

func ToInt32E

func ToInt32E(i interface{}, defaultValue ...int32) (value int32, err error)

ToInt32E casts an interface to an int32 type.

func ToInt64

func ToInt64(i interface{}, defaultValue ...int64) int64

func ToInt64E

func ToInt64E(i interface{}, defaultValue ...int64) (value int64, err error)

ToInt64E casts an interface to an int64 type.

func ToInt8

func ToInt8(i interface{}, defaultValue ...int8) int8

func ToInt8E

func ToInt8E(i interface{}, defaultValue ...int8) (value int8, err error)

ToInt8E casts an interface to an int8 type.

func ToIntE

func ToIntE(i interface{}, defaultValue ...int) (value int, err error)

ToIntE casts an interface to an int type.

func ToIntSlice

func ToIntSlice(i interface{}, seperator ...string) []int

func ToIntSliceE

func ToIntSliceE(i interface{}, seperator ...string) (value []int, err error)

ToIntSliceE casts an interface to a []int type.

func ToMap

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

func ToMapE

func ToMapE(i interface{}) (value map[string]interface{}, err error)

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

func ToMapSlice

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

func ToMapSliceE

func ToMapSliceE(i interface{}) (value []map[string]interface{}, err error)

func ToSlice

func ToSlice(i interface{}, seperator ...string) []interface{}

func ToSliceE

func ToSliceE(i interface{}, seperator ...string) (value []interface{}, err error)

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

func ToString

func ToString(i interface{}, defaultValue ...string) string

func ToStringE

func ToStringE(i interface{}, defaultValue ...string) (value string, err error)

ToStringE casts an interface to a string type.

func ToStringSlice

func ToStringSlice(i interface{}, seperator ...string) []string

func ToStringSliceE

func ToStringSliceE(i interface{}, seperator ...string) (value []string, err error)

ToStringSliceE casts an interface to a []string type.

func ToTime

func ToTime(i interface{}, timeFormat ...string) time.Time

func ToTimeE

func ToTimeE(i interface{}, timeFormat ...string) (value time.Time, err error)

ToTimeE casts an interface to a time.Time type.

func ToTimeSlice

func ToTimeSlice(i interface{}, timeFormatAndSeperator ...string) []time.Time

func ToTimeSliceE

func ToTimeSliceE(i interface{}, timeFormatAndSeperator ...string) (value []time.Time, err error)

ToTimeSliceE casts an interface to a []time.Time type. timeFormatAndSeperator 1: timeFormat, 2:seperator, empty string "" to skip parameter

func ToTimeString

func ToTimeString(i interface{}, timeFormat ...string) string

ToTimeString. timeFormat[0] : format of time string, timeFormat[1] : if interface string optionly provide specific format

func ToTimeStringE

func ToTimeStringE(i interface{}, timeFormat ...string) (value string, err error)

ToTimeStringE casts an interface to a time string. timeFormat[0] : format of time string, timeFormat[1] : if interface string optionly provide specific format

func ToUint

func ToUint(i interface{}, defaultValue ...uint) uint

func ToUint16

func ToUint16(i interface{}, defaultValue ...uint16) uint16

func ToUint16E

func ToUint16E(i interface{}, defaultValue ...uint16) (value uint16, err error)

ToUint16E casts an interface to a uint16 type.

func ToUint32

func ToUint32(i interface{}, defaultValue ...uint32) uint32

func ToUint32E

func ToUint32E(i interface{}, defaultValue ...uint32) (value uint32, err error)

ToUint32E casts an interface to a uint32 type.

func ToUint64

func ToUint64(i interface{}, defaultValue ...uint64) uint64

func ToUint64E

func ToUint64E(i interface{}, defaultValue ...uint64) (value uint64, err error)

ToUint64E casts an interface to a uint64 type.

func ToUint8

func ToUint8(i interface{}, defaultValue ...uint8) uint8

func ToUint8E

func ToUint8E(i interface{}, defaultValue ...uint8) (value uint8, err error)

ToUint8E casts an interface to a uint type.

func ToUintE

func ToUintE(i interface{}, defaultValue ...uint) (value uint, err error)

ToUintE casts an interface to a uint type.

func ToValueMap

func ToValueMap(i interface{}) map[string]Value

func ToValueMapE

func ToValueMapE(i interface{}) (value map[string]Value, err error)

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

Types

type Value

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

Value type

func New

func New(i interface{}) Value

New value

func ToMapGet

func ToMapGet(i interface{}, path string) Value

func ToMapGetE

func ToMapGetE(i interface{}, path string) (Value, error)

func ToValueSlice

func ToValueSlice(i interface{}, seperator ...string) []Value

func ToValueSliceE

func ToValueSliceE(i interface{}, seperator ...string) (value []Value, err error)

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

func (Value) Bool

func (v Value) Bool(boolTrue ...string) bool

Bool ...

func (Value) BoolSlice

func (v Value) BoolSlice(boolTrueAndSeperator ...string) []bool

BoolSlice ... boolTrueAndSeperator 1: boolTrue, 2:seperator, empty string "" to skip parameter

func (Value) Float32

func (v Value) Float32(defaultValue ...float32) float32

Float32 ...

func (Value) Float64

func (v Value) Float64(defaultValue ...float64) float64

Float64 ...

func (Value) Int

func (v Value) Int(defaultValue ...int) int

Int ...

func (Value) Int16

func (v Value) Int16(defaultValue ...int16) int16

Int16 ...

func (Value) Int32

func (v Value) Int32(defaultValue ...int32) int32

Int32 ...

func (Value) Int64

func (v Value) Int64(defaultValue ...int64) int64

Int64 ...

func (Value) Int8

func (v Value) Int8(defaultValue ...int8) int8

Int8 ...

func (Value) IntSlice

func (v Value) IntSlice(seperator ...string) []int

IntSlice ...

func (Value) Interface

func (v Value) Interface(defaultValue ...interface{}) interface{}

Interface ...

func (Value) IsEmpty

func (v Value) IsEmpty() bool

IsEmpty ...

func (Value) IsNil

func (v Value) IsNil() bool

IsNil ...

func (Value) Map

func (v Value) Map() map[string]interface{}

Map ...

func (Value) MapGet

func (v Value) MapGet(path string) Value

MapGet ...

func (Value) MapSlice

func (v Value) MapSlice() []map[string]interface{}

MapSlice ...

func (Value) Slice

func (v Value) Slice(seperator ...string) []interface{}

Slice ...

func (Value) String

func (v Value) String(defaultValue ...string) string

String ...

func (Value) StringSlice

func (v Value) StringSlice(seperator ...string) []string

StringSlice ...

func (Value) Time

func (v Value) Time(timeFormat ...string) time.Time

Time ...

func (Value) TimeSlice

func (v Value) TimeSlice(timeFormatAndSeperator ...string) []time.Time

TimeSlice ... timeFormatAndSeperator 1: timeFormat, 2:seperator, empty string "" to skip parameter

func (Value) TimeString

func (v Value) TimeString(timeFormat ...string) string

TimeString. timeFormat[0] : format of time string, timeFormat[1] : if interface string optionly provide specific format

func (Value) Uint

func (v Value) Uint(defaultValue ...uint) uint

Uint ...

func (Value) Uint16

func (v Value) Uint16(defaultValue ...uint16) uint16

Uint16 ...

func (Value) Uint32

func (v Value) Uint32(defaultValue ...uint32) uint32

Uint32 ...

func (Value) Uint64

func (v Value) Uint64(defaultValue ...uint64) uint64

Uint64 ...

func (Value) Uint8

func (v Value) Uint8(defaultValue ...uint8) uint8

Uint8 ...

func (Value) ValueMap

func (v Value) ValueMap() map[string]Value

ValueMap ...

func (Value) ValueSlice

func (v Value) ValueSlice(seperator ...string) []Value

ValueSlice ...

Jump to

Keyboard shortcuts

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