typ

package module
Version: v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: MIT Imports: 12 Imported by: 0

README

Typ

GoDoc Build Status Coverage Status Go Report Card

Typ is a library providing a powerful interface to impressive user experience with conversion and fetching data from built-in types in Golang

Features

  • Safe conversion along built-in types like as bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, complex64, complex128, string
  • Null types for all primitive types with supported interfaces: json.Unmarshaler, json.Marshaler, sql.Scanner, driver.Valuer
  • Value retriever for multidimensional unstructured data from interface
  • Conversion functions present via interface (reflection) and native types for better performance
  • Some humanize string conversion functions

Installation

Use go get to install the latest version of the library.

    go get -u github.com/gurukami/typ

Then include package in your application and enjoy.

    import "github.com/gurukami/typ"

Usage

Of(interface{}) conversion from interface value to built-in type

// typ.Of(v interface{}, options ...Option).{Type}(defaultValue ...{Type})
//
// Where {Type} any of 
//      Bool, 
//      Int, Int8, Int16, Int32, Int64, 
//      Uint, Uint8, Uint16, Uint32, Uint64, 
//      Float32, Float, 
//      Complex64, Complex, 
//      String
//
// All methods for conversion returns Null{Type} struct with helpful methods & fields
//
//  fields:
//      P - pointer to value
//      Error - conversion error
//
//  methods:
//      V() - value of type
//      Present() - determines whether a value has been set
//      Valid() - determines whether a value has been valid (without error)
//      
//      Scan(value interface{})         | sql.Scanner
//      Value() (driver.Value, error)   | driver.Valuer
//
//      UnmarshalJSON(b []byte) error   | json.Unmarshaler
//      MarshalJSON() ([]byte, error)   | json.Marshaler

// Valid
nv := typ.Of(3.1415926535, typ.FmtByte('g'), typ.Precision(4)).String()
fmt.Printf("Value: %v, Valid: %v, Present: %v, Error: %v\n", nv.V(), nv.Valid(), nv.Present(), nv.Error)
// Output: Value: 3.142, Valid: true, Present: true, Error: <nil>

// Not valid
nv = typ.Of(3.1415926535).Int()
fmt.Printf("Value: %v, Valid: %v, Present: %v, Error: %v\n", nv.V(), nv.Valid(), nv.Present(), nv.Error)
// Output: Value: 3, Valid: false, Present: true, Error: value can't safely convert

Native conversion without reflection when type is know

// For the best performance always use this way if you know about exact type
//
// typ.{FromType}{ToType}(value , [options ...{FromType}{ToType}Option]).V()
// 
// Where {FromType}, {ToType} any of 
//      Bool, 
//      Int, Int8, Int16, Int32, Int64, 
//      Uint, Uint8, Uint16, Uint32, Uint64, 
//      Float32, Float, 
//      Complex64, Complex, 
//      String
//
// All methods for conversion returns Null{Type} struct with helpful methods & fields, additional info you can read in example above

// Valid
nv := typ.FloatString(3.1415926535, typ.FloatStringFmtByte('g'), typ.FloatStringPrecision(4))
fmt.Printf("Value: %v, Valid: %v, Present: %v, Error: %v\n", nv.V(), nv.Valid(), nv.Present(), nv.Error)
// Output: Value: 3.142, Valid: true, Present: true, Error: <nil>

// Not valid
nv = typ.FloatInt(3.1415926535)
fmt.Printf("Value: %v, Valid: %v, Present: %v, Error: %v\n", nv.V(), nv.Valid(), nv.Present(), nv.Error)
// Output: Value: 3, Valid: false, Present: true, Error: value can't safely convert

Retrieve multidimensional unstructured data from interface

data := map[int]interface{}{
   0: []interface{}{
      0: map[string]int{
         "0": 42,
      },
   },
}

// Instead of do something like this 
//  data[0].([]interface{})[0].(map[string]int)["0”]
//      and not caught a panic
// use this

// Value exists
nv := typ.Of(data).Get(0, 0, "0").Interface()
fmt.Printf("Value: %v, Valid: %v, Present: %v, Error: %v\n", nv.V(), nv.Valid(), nv.Present(), nv.Error)
// Output: Value: 42, Valid: true, Present: true, Error: <nil>

// Value not exists
nv = typ.Of(data).Get(3, 7, "5").Interface()
fmt.Printf("Value: %v, Valid: %v, Present: %v, Error: %v\n", nv.V(), nv.Valid(), nv.Present(), nv.Error)
// Output: Value: <nil>, Valid: false, Present: false, Error: out of bounds on given data

Rules of safely type conversion along types

From / to Bool Int* String Uint* Float* Complex*
Bool + + + + + +
Int* + + formatting >= 0 24bit or 53bit real, 24bit or 53bit
String parsing parsing + parsing parsing parsing
Uint* + 63bit formatting + 24bit or 53bit 24bit or 53bit
Float* + 24bit or 53bit formatting >= 0, 24bit or 53bit + +
Complex* + real, 24bit or 53bit + >= 0, real, 24bit or 53bit real +

* based on bit size capacity, 8,16,32,64 for Int,Uint; 32,64 for Float,Complex

Donation for amazing goal

I like airplanes and i want to get private pilot licence, and i believe you can help me to make my dream come true :)

>>>>>>>>>> Make a dream come true <<<<<<<<<<

License

The MIT license
Copyright (c) 2019 Gurukami

Documentation

Index

Constants

View Source
const (
	MinFloat32        = float32(-3.40282346638528859811704183484516925440e+38)
	MaxFloat32        = float32(3.40282346638528859811704183484516925440e+38)
	MinSafeIntFloat32 = float32(-1.6777215e+07)
	MaxSafeIntFloat32 = float32(1.6777215e+07)
	MinFloat64        = float64(-1.797693134862315708145274237317043567981e+308)
	MaxFloat64        = float64(1.797693134862315708145274237317043567981e+308)
	MinSafeIntFloat64 = float64(-9.007199254740991e+15)
	MaxSafeIntFloat64 = float64(9.007199254740991e+15)
	MaxInt8           = int8(127)
	MinInt8           = int8(-128)
	MaxInt16          = int16(32767)
	MinInt16          = int16(-32768)
	MaxInt32          = int32(2147483647)
	MinInt32          = int32(-2147483648)
	MaxInt64          = int64(9223372036854775807)
	MinInt64          = int64(-9223372036854775808)
	MaxInt            = int(9223372036854775807)
	MinInt            = int(-9223372036854775808)
	MaxUint8          = uint8(255)
	MaxUint16         = uint16(65535)
	MaxUint32         = uint32(4294967295)
	MaxUint64         = uint64(18446744073709551615)
	MaxUint           = uint64(18446744073709551615)
)

Min and Max values in primitive types

Variables

View Source
var (
	// ErrConvert is returned when value can't safely convert
	ErrConvert = ErrorConvert(errors.New("value can't safely convert"))
	// ErrOutOfRange is returned when value out of range on given data
	ErrOutOfRange = ErrorOutOfRange(errors.New("out of range on given data"))
	// ErrOutOfBounds is returned when value out of bounds on given data
	ErrOutOfBounds = ErrorOutOfBounds(errors.New("out of bounds on given data"))
	// ErrUnexpectedValue is returned when unexpected value given on data
	ErrUnexpectedValue = ErrorUnexpectedValue(errors.New("unexpected value given on data"))
	// ErrInvalidArgument is returned when invalid argument is present
	ErrInvalidArgument = ErrorInvalidArgument(errors.New("invalid argument"))
	// ErrDefaultValue is returned when default value is ambiguous
	ErrDefaultValue = ErrorInvalidArgument(errors.New("default value is ambiguous"))
)
View Source
var (
	// ErrBaseInvalid is returned when a base option has invalid range
	ErrBaseInvalid = ErrorInvalidArgument(errors.New("base option must be in range 2 <= base <= 36"))
	// ErrFmtByteInvalid is returned when a fmt byte has invalid value
	ErrFmtByteInvalid = ErrorInvalidArgument(errors.New("fmtByte option must be one of 'b', 'e', 'E', 'f', 'g', 'G'"))
)

Functions

func NullBoolSlice

func NullBoolSlice(null []NullBool, valid bool) []bool

NullBoolSlice returns slice of bool with filled values from slice of NullBool

func NullComplex64Slice

func NullComplex64Slice(null []NullComplex64, valid bool) []complex64

NullComplex64Slice returns slice of complex64 with filled values from slice of NullComplex64

func NullComplexSlice

func NullComplexSlice(null []NullComplex, valid bool) []complex128

NullComplexSlice returns slice of complex128 with filled values from slice of NullComplex

func NullFloat32Slice

func NullFloat32Slice(null []NullFloat32, valid bool) []float32

NullFloat32Slice returns slice of float32 with filled values from slice of NullFloat32

func NullFloatSlice

func NullFloatSlice(null []NullFloat, valid bool) []float64

NullFloatSlice returns slice of float64 with filled values from slice of NullFloat

func NullInt16Slice

func NullInt16Slice(null []NullInt16, valid bool) []int16

NullInt16Slice returns slice of int16 with filled values from slice of NullInt16

func NullInt32Slice

func NullInt32Slice(null []NullInt32, valid bool) []int32

NullInt32Slice returns slice of int32 with filled values from slice of NullInt32

func NullInt64Slice

func NullInt64Slice(null []NullInt64, valid bool) []int64

NullInt64Slice returns slice of int64 with filled values from slice of NullInt64

func NullInt8Slice

func NullInt8Slice(null []NullInt8, valid bool) []int8

NullInt8Slice returns slice of int8 with filled values from slice of NullInt8

func NullIntSlice

func NullIntSlice(null []NullInt, valid bool) []int

NullIntSlice returns slice of int with filled values from slice of NullInt

func NullInterfaceSlice

func NullInterfaceSlice(null []NullInterface, valid bool) []interface{}

NullInterfaceSlice returns slice of interface{} with filled values from slice of NullInterface

func NullStringSlice

func NullStringSlice(null []NullString, valid bool) []string

NullStringSlice returns slice of string with filled values from slice of NullString

func NullTimeSlice

func NullTimeSlice(null []NullTime, valid bool) []time.Time

NullTimeSlice returns slice of time.Time with filled values from slice of NullTime

func NullUint16Slice

func NullUint16Slice(null []NullUint16, valid bool) []uint16

NullUint16Slice returns slice of uint16 with filled values from slice of NullUint16

func NullUint32Slice

func NullUint32Slice(null []NullUint32, valid bool) []uint32

NullUint32Slice returns slice of uint32 with filled values from slice of NullUint32

func NullUint64Slice

func NullUint64Slice(null []NullUint64, valid bool) []uint64

NullUint64Slice returns slice of uint64 with filled values from slice of NullUint64

func NullUint8Slice

func NullUint8Slice(null []NullUint8, valid bool) []uint8

NullUint8Slice returns slice of uint8 with filled values from slice of NullUint8

func NullUintSlice

func NullUintSlice(null []NullUint, valid bool) []uint

NullUintSlice returns slice of uint with filled values from slice of NullUint

func NumericToString

func NumericToString(v interface{}, base int, fmtByte byte, prec int) string

NumericToString convert from any numeric type to string in the given base for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10. The format fmt is one of 'b' (-ddddp±ddd, a binary exponent), 'e' (-d.dddde±dd, a decimal exponent), 'E' (-d.ddddE±dd, a decimal exponent), 'f' (-ddd.dddd, no exponent), 'g' ('e' for large exponents, 'f' otherwise), or 'G' ('E' for large exponents, 'f' otherwise). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.

Types

type ComplexStringOption

type ComplexStringOption func(*complexStrOpts) error

ComplexStringOption is interface function used as argument value for type conversion configuration from complex to string

func ComplexStringDefault

func ComplexStringDefault(value string) ComplexStringOption

ComplexStringDefault set default string value for complex conversion to string.

type ErrorConvert

type ErrorConvert error

ErrorConvert is returned when value can't safely convert

type ErrorInvalidArgument

type ErrorInvalidArgument error

ErrorInvalidArgument is returned when invalid argument is present

type ErrorOutOfBounds

type ErrorOutOfBounds error

ErrorOutOfBounds is returned when value out of bounds on given data

type ErrorOutOfRange

type ErrorOutOfRange error

ErrorOutOfRange is returned when value out of range on given data

type ErrorPanic

type ErrorPanic error

ErrorPanic is returned when fatal error is occurred

type ErrorUnexpectedValue

type ErrorUnexpectedValue error

ErrorUnexpectedValue is returned when unexpected value given on data

type FloatStringOption

type FloatStringOption func(*floatStrOpts) error

FloatStringOption is interface function used as argument value for type conversion configuration from float to string

func FloatStringBitSize

func FloatStringBitSize(value int) FloatStringOption

FloatStringBitSize set bit size for float conversion to string. The bitSize must be 32 or 64

func FloatStringDefault

func FloatStringDefault(value string) FloatStringOption

FloatStringDefault set default string value for float conversion to string.

func FloatStringFmtByte

func FloatStringFmtByte(value byte) FloatStringOption

FloatStringFmtByte set format for float conversion to string. The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. For 'e', 'E', and 'f' it is the number of digits after the decimal point. For 'g' and 'G' it is the maximum number of significant digits (trailing zeros are removed). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.

func FloatStringPrecision

func FloatStringPrecision(value int) FloatStringOption

FloatStringPrecision set precision for float conversion to string. The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. For 'e', 'E', and 'f' it is the number of digits after the decimal point. For 'g' and 'G' it is the maximum number of significant digits (trailing zeros are removed). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.

type IntStringOption

type IntStringOption func(*intStrOpts) error

IntStringOption is interface function used as argument value for type conversion configuration from int to string

func IntStringBase

func IntStringBase(value int) IntStringOption

IntStringBase set base for int conversion to string. The base must be 2 <= base <= 36 for digit values >= 10.

func IntStringDefault

func IntStringDefault(value string) IntStringOption

IntStringDefault set default string value for int conversion to string.

type NullBool

type NullBool struct {
	P     *bool
	Error error
}

NullBool represents an bool that may be null.

func NBool

func NBool(value bool) NullBool

NBool returns NullBool from bool

func StringBoolHumanize

func StringBoolHumanize(from string) (nv NullBool)

StringBoolHumanize convert value from string to bool. Returns false for string 'false' in case-insensitive mode or string equals '0'

func (NullBool) MarshalJSON

func (n NullBool) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullBool) Present

func (n NullBool) Present() bool

Present determines whether a value has been set

func (*NullBool) Scan

func (n *NullBool) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullBool) Set added in v1.1.0

func (n *NullBool) Set(value bool)

Set saves value into current struct

func (NullBool) Typ

func (n NullBool) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullBool) UnmarshalJSON

func (n *NullBool) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullBool) V

func (n NullBool) V() bool

V returns value of underlying type if it was set, otherwise default value

func (NullBool) Valid

func (n NullBool) Valid() bool

Valid determines whether a value has been valid

func (NullBool) Value

func (n NullBool) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullComplex

type NullComplex struct {
	P     *complex128
	Error error
}

NullComplex represents a complex128 that may be null.

func IntComplex

func IntComplex(from int64, defaultValue ...complex128) (nv NullComplex)

IntComplex convert value from int64 to complex128. Returns value if type can safely converted, otherwise error & default value in result values

func NComplex

func NComplex(value complex128) NullComplex

NComplex returns NullComplex from complex128

func StringComplex

func StringComplex(from string, defaultValue ...complex128) (nv NullComplex)

StringComplex convert value from string to complex128. Returns value if type can safely converted, otherwise error & default value in result values

func UintComplex

func UintComplex(from uint64, defaultValue ...complex128) (nv NullComplex)

UintComplex convert value from uint64 to complex128. Returns value if type can safely converted, otherwise error & default value in result values

func (NullComplex) MarshalJSON

func (n NullComplex) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullComplex) Present

func (n NullComplex) Present() bool

Present determines whether a value has been set

func (*NullComplex) Scan

func (n *NullComplex) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullComplex) Set added in v1.1.0

func (n *NullComplex) Set(value complex128)

Set saves value into current struct

func (NullComplex) Typ

func (n NullComplex) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullComplex) UnmarshalJSON

func (n *NullComplex) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullComplex) V

func (n NullComplex) V() complex128

V returns value of underlying type if it was set, otherwise default value

func (NullComplex) Valid

func (n NullComplex) Valid() bool

Valid determines whether a value has been valid

func (NullComplex) Value

func (n NullComplex) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullComplex64

type NullComplex64 struct {
	P     *complex64
	Error error
}

NullComplex64 represents an complex64 that may be null.

func Complex64

func Complex64(from complex128, defaultValue ...complex64) (nv NullComplex64)

Complex64 convert value from complex128 to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Complex64

func Float32Complex64(from float32, defaultValue ...complex64) (nv NullComplex64)

Float32Complex64 convert value from float32 to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func FloatComplex64

func FloatComplex64(from float64, defaultValue ...complex64) (nv NullComplex64)

FloatComplex64 convert value from float64 to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func IntComplex64

func IntComplex64(from int64, defaultValue ...complex64) (nv NullComplex64)

IntComplex64 convert value from int64 to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func NComplex64

func NComplex64(value complex64) NullComplex64

NComplex64 returns NullComplex64 from complex64

func StringComplex64

func StringComplex64(from string, defaultValue ...complex64) (nv NullComplex64)

StringComplex64 convert value from string to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func UintComplex64

func UintComplex64(from uint64, defaultValue ...complex64) (nv NullComplex64)

UintComplex64 convert value from uint64 to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func (NullComplex64) MarshalJSON

func (n NullComplex64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullComplex64) Present

func (n NullComplex64) Present() bool

Present determines whether a value has been set

func (*NullComplex64) Scan

func (n *NullComplex64) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullComplex64) Set added in v1.1.0

func (n *NullComplex64) Set(value complex64)

Set saves value into current struct

func (NullComplex64) Typ

func (n NullComplex64) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullComplex64) UnmarshalJSON

func (n *NullComplex64) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullComplex64) V

func (n NullComplex64) V() complex64

V returns value of underlying type if it was set, otherwise default value

func (NullComplex64) Valid

func (n NullComplex64) Valid() bool

Valid determines whether a value has been valid

func (NullComplex64) Value

func (n NullComplex64) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullFloat

type NullFloat struct {
	P     *float64
	Error error
}

NullFloat represents a float64 that may be null.

func Complex64Float64

func Complex64Float64(from complex64, defaultValue ...float64) (nv NullFloat)

Complex64Float64 convert value from complex64 to float64. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexFloat64

func ComplexFloat64(from complex128, defaultValue ...float64) (nv NullFloat)

ComplexFloat64 convert value from complex128 to float64. Returns value if type can safely converted, otherwise error & default value in result values

func IntFloat

func IntFloat(from int64, defaultValue ...float64) (nv NullFloat)

IntFloat convert value from int to float64. Returns value if type can safely converted, otherwise error & default value in result values

func NFloat

func NFloat(value float64) NullFloat

NFloat returns NullFloat from float64

func StringFloat

func StringFloat(from string, defaultValue ...float64) (nv NullFloat)

StringFloat convert value from string to float64. Returns value if type can safely converted, otherwise error & default value in result values

func UintFloat

func UintFloat(from uint64, defaultValue ...float64) (nv NullFloat)

UintFloat convert value from uint to float64. Returns value if type can safely converted, otherwise error & default value in result values

func (NullFloat) MarshalJSON

func (n NullFloat) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullFloat) Present

func (n NullFloat) Present() bool

Present determines whether a value has been set

func (*NullFloat) Scan

func (n *NullFloat) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullFloat) Set added in v1.1.0

func (n *NullFloat) Set(value float64)

Set saves value into current struct

func (NullFloat) Typ

func (n NullFloat) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullFloat) UnmarshalJSON

func (n *NullFloat) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullFloat) V

func (n NullFloat) V() float64

V returns value of underlying type if it was set, otherwise default value

func (NullFloat) Valid

func (n NullFloat) Valid() bool

Valid determines whether a value has been valid

func (NullFloat) Value

func (n NullFloat) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullFloat32

type NullFloat32 struct {
	P     *float32
	Error error
}

NullFloat32 represents a float32 that may be null.

func Complex64Float32

func Complex64Float32(from complex64, defaultValue ...float32) (nv NullFloat32)

Complex64Float32 convert value from complex64 to float32. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexFloat32

func ComplexFloat32(from complex128, defaultValue ...float32) (nv NullFloat32)

ComplexFloat32 convert value from complex128 to float32. Returns value if type can safely converted, otherwise error & default value in result values

func Float32

func Float32(from float64, defaultValue ...float32) (nv NullFloat32)

Float32 convert value from float64 to float32. Returns value if type can safely converted, otherwise error & default value in result values

func IntFloat32

func IntFloat32(from int64, defaultValue ...float32) (nv NullFloat32)

IntFloat32 convert value from int to float32. Returns value if type can safely converted, otherwise error & default value in result values

func NFloat32

func NFloat32(value float32) NullFloat32

NFloat32 returns NullFloat32 from float32

func StringFloat32

func StringFloat32(from string, defaultValue ...float32) (nv NullFloat32)

StringFloat32 convert value from string to float32. Returns value if type can safely converted, otherwise error & default value in result values

func UintFloat32

func UintFloat32(from uint64, defaultValue ...float32) (nv NullFloat32)

UintFloat32 convert value from uint to float32. Returns value if type can safely converted, otherwise error & default value in result values

func (NullFloat32) MarshalJSON

func (n NullFloat32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullFloat32) Present

func (n NullFloat32) Present() bool

Present determines whether a value has been set

func (*NullFloat32) Scan

func (n *NullFloat32) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullFloat32) Set added in v1.1.0

func (n *NullFloat32) Set(value float32)

Set saves value into current struct

func (NullFloat32) Typ

func (n NullFloat32) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullFloat32) UnmarshalJSON

func (n *NullFloat32) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullFloat32) V

func (n NullFloat32) V() float32

V returns value of underlying type if it was set, otherwise default value

func (NullFloat32) Valid

func (n NullFloat32) Valid() bool

Valid determines whether a value has been valid

func (NullFloat32) Value

func (n NullFloat32) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullInt

type NullInt struct {
	P     *int
	Error error
}

NullInt represents an int that may be null.

func Complex64Int

func Complex64Int(from complex64, defaultValue ...int) (nv NullInt)

Complex64Int convert value from complex64 to int. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexInt

func ComplexInt(from complex128, defaultValue ...int) (nv NullInt)

ComplexInt convert value from complex128 to int. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Int

func Float32Int(from float32, defaultValue ...int) (nv NullInt)

Float32Int convert value from float32 to int. Returns value if type can safely converted, otherwise error & default value in result values

func FloatInt

func FloatInt(from float64, defaultValue ...int) (nv NullInt)

FloatInt convert value from float64 to int. Returns value if type can safely converted, otherwise error & default value in result values

func NInt

func NInt(value int) NullInt

NInt returns NullInt from int

func StringInt

func StringInt(from string, defaultValue ...int) (nv NullInt)

StringInt convert value from string to int. Returns value if type can safely converted, otherwise error & default value in result values

func (NullInt) MarshalJSON

func (n NullInt) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullInt) Present

func (n NullInt) Present() bool

Present determines whether a value has been set

func (*NullInt) Scan

func (n *NullInt) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullInt) Set added in v1.1.0

func (n *NullInt) Set(value int)

Set saves value into current struct

func (NullInt) Typ

func (n NullInt) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullInt) UnmarshalJSON

func (n *NullInt) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullInt) V

func (n NullInt) V() int

V returns value of underlying type if it was set, otherwise default value

func (NullInt) Valid

func (n NullInt) Valid() bool

Valid determines whether a value has been valid

func (NullInt) Value

func (n NullInt) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullInt16

type NullInt16 struct {
	P     *int16
	Error error
}

NullInt16 represents an int16 that may be null.

func Complex64Int16

func Complex64Int16(from complex64, defaultValue ...int16) (nv NullInt16)

Complex64Int16 convert value from complex64 to int16. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexInt16

func ComplexInt16(from complex128, defaultValue ...int16) (nv NullInt16)

ComplexInt16 convert value from complex128 to int16. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Int16

func Float32Int16(from float32, defaultValue ...int16) (nv NullInt16)

Float32Int16 convert value from float32 to int16. Returns value if type can safely converted, otherwise error & default value in result values

func FloatInt16

func FloatInt16(from float64, defaultValue ...int16) (nv NullInt16)

FloatInt16 convert value from float64 to int16. Returns value if type can safely converted, otherwise error & default value in result values

func Int16

func Int16(from int64, defaultValue ...int16) (nv NullInt16)

Int16 convert value from int64 to int16. Returns value if type can safely converted, otherwise error & default value in result values

func NInt16

func NInt16(value int16) NullInt16

NInt16 returns NullInt16 from int16

func StringInt16

func StringInt16(from string, defaultValue ...int16) (nv NullInt16)

StringInt16 convert value from string to int16. Returns value if type can safely converted, otherwise error & default value in result values

func UintInt16

func UintInt16(from uint64, defaultValue ...int16) (nv NullInt16)

UintInt16 convert value from uint64 to int16. Returns value if type can safely converted, otherwise error & default value in result values

func (NullInt16) MarshalJSON

func (n NullInt16) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullInt16) Present

func (n NullInt16) Present() bool

Present determines whether a value has been set

func (*NullInt16) Scan

func (n *NullInt16) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullInt16) Set added in v1.1.0

func (n *NullInt16) Set(value int16)

Set saves value into current struct

func (NullInt16) Typ

func (n NullInt16) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullInt16) UnmarshalJSON

func (n *NullInt16) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullInt16) V

func (n NullInt16) V() int16

V returns value of underlying type if it was set, otherwise default value

func (NullInt16) Valid

func (n NullInt16) Valid() bool

Valid determines whether a value has been valid

func (NullInt16) Value

func (n NullInt16) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullInt32

type NullInt32 struct {
	P     *int32
	Error error
}

NullInt32 represents an int32 that may be null.

func Complex64Int32

func Complex64Int32(from complex64, defaultValue ...int32) (nv NullInt32)

Complex64Int32 convert value from complex64 to int32. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexInt32

func ComplexInt32(from complex128, defaultValue ...int32) (nv NullInt32)

ComplexInt32 convert value from complex128 to int32. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Int32

func Float32Int32(from float32, defaultValue ...int32) (nv NullInt32)

Float32Int32 convert value from float32 to int32. Returns value if type can safely converted, otherwise error & default value in result values

func FloatInt32

func FloatInt32(from float64, defaultValue ...int32) (nv NullInt32)

FloatInt32 convert value from float64 to int32. Returns value if type can safely converted, otherwise error & default value in result values

func Int32

func Int32(from int64, defaultValue ...int32) (nv NullInt32)

Int32 convert value from int64 to int32. Returns value if type can safely converted, otherwise error & default value in result values

func NInt32

func NInt32(value int32) NullInt32

NInt32 returns NullInt32 from int32

func StringInt32

func StringInt32(from string, defaultValue ...int32) (nv NullInt32)

StringInt32 convert value from string to int32. Returns value if type can safely converted, otherwise error & default value in result values

func UintInt32

func UintInt32(from uint64, defaultValue ...int32) (nv NullInt32)

UintInt32 convert value from uint64 to int32. Returns value if type can safely converted, otherwise error & default value in result values

func (NullInt32) MarshalJSON

func (n NullInt32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullInt32) Present

func (n NullInt32) Present() bool

Present determines whether a value has been set

func (*NullInt32) Scan

func (n *NullInt32) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullInt32) Set added in v1.1.0

func (n *NullInt32) Set(value int32)

Set saves value into current struct

func (NullInt32) Typ

func (n NullInt32) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullInt32) UnmarshalJSON

func (n *NullInt32) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullInt32) V

func (n NullInt32) V() int32

V returns value of underlying type if it was set, otherwise default value

func (NullInt32) Valid

func (n NullInt32) Valid() bool

Valid determines whether a value has been valid

func (NullInt32) Value

func (n NullInt32) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullInt64

type NullInt64 struct {
	P     *int64
	Error error
}

NullInt64 represents an int64 that may be null.

func Complex64Int64

func Complex64Int64(from complex64, defaultValue ...int64) (nv NullInt64)

Complex64Int64 convert value from complex64 to int64. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexInt64

func ComplexInt64(from complex128, defaultValue ...int64) (nv NullInt64)

ComplexInt64 convert value from complex128 to int64. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Int64

func Float32Int64(from float32, defaultValue ...int64) (nv NullInt64)

Float32Int64 convert value from float32 to int64. Returns value if type can safely converted, otherwise error & default value in result values

func FloatInt64

func FloatInt64(from float64, defaultValue ...int64) (nv NullInt64)

FloatInt64 convert value from float64 to int64. Returns value if type can safely converted, otherwise error & default value in result values

func NInt64

func NInt64(value int64) NullInt64

NInt64 returns NullInt64 from int64

func StringInt64

func StringInt64(from string, defaultValue ...int64) (nv NullInt64)

StringInt64 convert value from string to int64. Returns value if type can safely converted, otherwise error & default value in result values

func UintInt64

func UintInt64(from uint64, defaultValue ...int64) (nv NullInt64)

UintInt64 convert value from uint64 to int64. Returns value if type can safely converted, otherwise error & default value in result values

func (NullInt64) MarshalJSON

func (n NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullInt64) Present

func (n NullInt64) Present() bool

Present determines whether a value has been set

func (*NullInt64) Scan

func (n *NullInt64) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullInt64) Set added in v1.1.0

func (n *NullInt64) Set(value int64)

Set saves value into current struct

func (NullInt64) Typ

func (n NullInt64) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullInt64) UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullInt64) V

func (n NullInt64) V() int64

V returns value of underlying type if it was set, otherwise default value

func (NullInt64) Valid

func (n NullInt64) Valid() bool

Valid determines whether a value has been valid

func (NullInt64) Value

func (n NullInt64) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullInt8

type NullInt8 struct {
	P     *int8
	Error error
}

NullInt8 represents an int8 that may be null.

func Complex64Int8

func Complex64Int8(from complex64, defaultValue ...int8) (nv NullInt8)

Complex64Int8 convert value from complex64 to int8. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexInt8

func ComplexInt8(from complex128, defaultValue ...int8) (nv NullInt8)

ComplexInt8 convert value from complex128 to int8. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Int8

func Float32Int8(from float32, defaultValue ...int8) (nv NullInt8)

Float32Int8 convert value from float32 to int8. Returns value if type can safely converted, otherwise error & default value in result values

func FloatInt8

func FloatInt8(from float64, defaultValue ...int8) (nv NullInt8)

FloatInt8 convert value from float64 to int8. Returns value if type can safely converted, otherwise error & default value in result values

func Int8

func Int8(from int64, defaultValue ...int8) (nv NullInt8)

Int8 convert value from int64 to int8. Returns value if type can safely converted, otherwise error & default value in result values

func NInt8

func NInt8(value int8) NullInt8

NInt8 returns NullInt8 from int8

func StringInt8

func StringInt8(from string, defaultValue ...int8) (nv NullInt8)

StringInt8 convert value from string to int8. Returns value if type can safely converted, otherwise error & default value in result values

func UintInt8

func UintInt8(from uint64, defaultValue ...int8) (nv NullInt8)

UintInt8 convert value from uint64 to int8. Returns value if type can safely converted, otherwise error & default value in result values

func (NullInt8) MarshalJSON

func (n NullInt8) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullInt8) Present

func (n NullInt8) Present() bool

Present determines whether a value has been set

func (*NullInt8) Scan

func (n *NullInt8) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullInt8) Set added in v1.1.0

func (n *NullInt8) Set(value int8)

Set saves value into current struct

func (NullInt8) Typ

func (n NullInt8) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullInt8) UnmarshalJSON

func (n *NullInt8) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullInt8) V

func (n NullInt8) V() int8

V returns value of underlying type if it was set, otherwise default value

func (NullInt8) Valid

func (n NullInt8) Valid() bool

Valid determines whether a value has been valid

func (NullInt8) Value

func (n NullInt8) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullInterface

type NullInterface struct {
	P     interface{}
	Error error
}

NullInterface represents an interface{} that may be null.

func NInterface

func NInterface(value interface{}) NullInterface

NInterface returns NullInterface from interface{}

func (NullInterface) MarshalJSON

func (n NullInterface) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullInterface) Present

func (n NullInterface) Present() bool

Present determines whether a value has been set

func (*NullInterface) Scan

func (n *NullInterface) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullInterface) Set added in v1.1.0

func (n *NullInterface) Set(value interface{})

Set saves value into current struct

func (NullInterface) Typ

func (n NullInterface) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullInterface) UnmarshalJSON

func (n *NullInterface) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullInterface) V

func (n NullInterface) V() interface{}

V returns value of underlying type if it was set, otherwise default value

func (NullInterface) Valid

func (n NullInterface) Valid() bool

Valid determines whether a value has been valid

func (NullInterface) Value

func (n NullInterface) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullString

type NullString struct {
	P     *string
	Error error
}

NullString represents a string that may be null.

func BoolString

func BoolString(from bool) (nv NullString)

BoolString convert value from bool to string

func ComplexString

func ComplexString(from complex128, options ...ComplexStringOption) (nv NullString)

ComplexString convert value from complex128 to string

func Concat

func Concat(values []interface{}, options ...Option) NullString

Concat returns concatenated interface values to string

func FloatString

func FloatString(from float64, options ...FloatStringOption) (nv NullString)

FloatString convert value from float to string

func IntString

func IntString(from int64, options ...IntStringOption) (nv NullString)

IntString convert value from int64 to string

func NString

func NString(value string) NullString

NString returns NullString from string

func UintString

func UintString(from uint64, options ...UintStringOption) (nv NullString)

UintString convert value from uint64 to string

func (NullString) MarshalJSON

func (n NullString) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullString) Present

func (n NullString) Present() bool

Present determines whether a value has been set

func (*NullString) Scan

func (n *NullString) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullString) Set added in v1.1.0

func (n *NullString) Set(value string)

Set saves value into current struct

func (NullString) Typ

func (n NullString) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullString) UnmarshalJSON

func (n *NullString) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullString) V

func (n NullString) V() string

V returns value of underlying type if it was set, otherwise default value

func (NullString) Valid

func (n NullString) Valid() bool

Valid determines whether a value has been valid

func (NullString) Value

func (n NullString) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullTime

type NullTime struct {
	P     *time.Time
	Error error
}

NullTime represents a time.Time that may be null.

func NTime

func NTime(value time.Time) NullTime

NTime returns NullTime from time.Time

func (NullTime) MarshalJSON

func (n NullTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullTime) Present

func (n NullTime) Present() bool

Present determines whether a value has been set

func (*NullTime) Scan

func (n *NullTime) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullTime) Set added in v1.1.0

func (n *NullTime) Set(value time.Time)

Set saves value into current struct

func (*NullTime) UnmarshalJSON

func (n *NullTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullTime) V

func (n NullTime) V() time.Time

V returns value of underlying type if it was set, otherwise default value

func (NullTime) Valid

func (n NullTime) Valid() bool

Valid determines whether a value has been valid

func (NullTime) Value

func (n NullTime) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullUint

type NullUint struct {
	P     *uint
	Error error
}

NullUint represents a uint that may be null.

func Complex64Uint

func Complex64Uint(from complex64, defaultValue ...uint) (nv NullUint)

Complex64Uint convert value from complex64 to uint. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexUint

func ComplexUint(from complex128, defaultValue ...uint) (nv NullUint)

ComplexUint convert value from complex128 to uint. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Uint

func Float32Uint(from float32, defaultValue ...uint) (nv NullUint)

Float32Uint convert value from float32 to uint. Returns value if type can safely converted, otherwise error & default value in result values

func FloatUint

func FloatUint(from float64, defaultValue ...uint) (nv NullUint)

FloatUint convert value from float64 to uint. Returns value if type can safely converted, otherwise error & default value in result values

func NUint

func NUint(value uint) NullUint

NUint returns NullUint from uint

func StringUint

func StringUint(from string, defaultValue ...uint) (nv NullUint)

StringUint convert value from string to uint. Returns value if type can safely converted, otherwise error & default value in result values

func (NullUint) MarshalJSON

func (n NullUint) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullUint) Present

func (n NullUint) Present() bool

Present determines whether a value has been set

func (*NullUint) Scan

func (n *NullUint) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullUint) Set added in v1.1.0

func (n *NullUint) Set(value uint)

Set saves value into current struct

func (NullUint) Typ

func (n NullUint) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullUint) UnmarshalJSON

func (n *NullUint) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullUint) V

func (n NullUint) V() uint

V returns value of underlying type if it was set, otherwise default value

func (NullUint) Valid

func (n NullUint) Valid() bool

Valid determines whether a value has been valid

func (NullUint) Value

func (n NullUint) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullUint16

type NullUint16 struct {
	P     *uint16
	Error error
}

NullUint16 represents a uint16 that may be null.

func Complex64Uint16

func Complex64Uint16(from complex64, defaultValue ...uint16) (nv NullUint16)

Complex64Uint16 convert value from complex64 to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexUint16

func ComplexUint16(from complex128, defaultValue ...uint16) (nv NullUint16)

ComplexUint16 convert value from complex128 to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Uint16

func Float32Uint16(from float32, defaultValue ...uint16) (nv NullUint16)

Float32Uint16 convert value from float32 to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func FloatUint16

func FloatUint16(from float64, defaultValue ...uint16) (nv NullUint16)

FloatUint16 convert value from float64 to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func IntUint16

func IntUint16(from int64, defaultValue ...uint16) (nv NullUint16)

IntUint16 convert value from int64 to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func NUint16

func NUint16(value uint16) NullUint16

NUint16 returns NullUint16 from uint16

func StringUint16

func StringUint16(from string, defaultValue ...uint16) (nv NullUint16)

StringUint16 convert value from string to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func Uint16

func Uint16(from uint64, defaultValue ...uint16) (nv NullUint16)

Uint16 convert value from uint64 to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func (NullUint16) MarshalJSON

func (n NullUint16) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullUint16) Present

func (n NullUint16) Present() bool

Present determines whether a value has been set

func (*NullUint16) Scan

func (n *NullUint16) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullUint16) Set added in v1.1.0

func (n *NullUint16) Set(value uint16)

Set saves value into current struct

func (NullUint16) Typ

func (n NullUint16) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullUint16) UnmarshalJSON

func (n *NullUint16) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullUint16) V

func (n NullUint16) V() uint16

V returns value of underlying type if it was set, otherwise default value

func (NullUint16) Valid

func (n NullUint16) Valid() bool

Valid determines whether a value has been valid

func (NullUint16) Value

func (n NullUint16) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullUint32

type NullUint32 struct {
	P     *uint32
	Error error
}

NullUint32 represents a uint32 that may be null.

func Complex64Uint32

func Complex64Uint32(from complex64, defaultValue ...uint32) (nv NullUint32)

Complex64Uint32 convert value from complex64 to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexUint32

func ComplexUint32(from complex128, defaultValue ...uint32) (nv NullUint32)

ComplexUint32 convert value from complex128 to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Uint32

func Float32Uint32(from float32, defaultValue ...uint32) (nv NullUint32)

Float32Uint32 convert value from float32 to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func FloatUint32

func FloatUint32(from float64, defaultValue ...uint32) (nv NullUint32)

FloatUint32 convert value from float64 to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func IntUint32

func IntUint32(from int64, defaultValue ...uint32) (nv NullUint32)

IntUint32 convert value from int64 to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func NUint32

func NUint32(value uint32) NullUint32

NUint32 returns NullUint32 from uint32

func StringUint32

func StringUint32(from string, defaultValue ...uint32) (nv NullUint32)

StringUint32 convert value from string to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func Uint32

func Uint32(from uint64, defaultValue ...uint32) (nv NullUint32)

Uint32 convert value from uint64 to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func (NullUint32) MarshalJSON

func (n NullUint32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullUint32) Present

func (n NullUint32) Present() bool

Present determines whether a value has been set

func (*NullUint32) Scan

func (n *NullUint32) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullUint32) Set added in v1.1.0

func (n *NullUint32) Set(value uint32)

Set saves value into current struct

func (NullUint32) Typ

func (n NullUint32) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullUint32) UnmarshalJSON

func (n *NullUint32) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullUint32) V

func (n NullUint32) V() uint32

V returns value of underlying type if it was set, otherwise default value

func (NullUint32) Valid

func (n NullUint32) Valid() bool

Valid determines whether a value has been valid

func (NullUint32) Value

func (n NullUint32) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullUint64

type NullUint64 struct {
	P     *uint64
	Error error
}

NullUint64 represents a uint64 that may be null.

func Complex64Uint64

func Complex64Uint64(from complex64, defaultValue ...uint64) (nv NullUint64)

Complex64Uint64 convert value from complex64 to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexUint64

func ComplexUint64(from complex128, defaultValue ...uint64) (nv NullUint64)

ComplexUint64 convert value from complex128 to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Uint64

func Float32Uint64(from float32, defaultValue ...uint64) (nv NullUint64)

Float32Uint64 convert value from float32 to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func FloatUint64

func FloatUint64(from float64, defaultValue ...uint64) (nv NullUint64)

FloatUint64 convert value from float64 to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func IntUint64

func IntUint64(from int64, defaultValue ...uint64) (nv NullUint64)

IntUint64 convert value from int64 to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func NUint64

func NUint64(value uint64) NullUint64

NUint64 returns NullUint64 from uint64

func StringUint64

func StringUint64(from string, defaultValue ...uint64) (nv NullUint64)

StringUint64 convert value from string to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func (NullUint64) MarshalJSON

func (n NullUint64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullUint64) Present

func (n NullUint64) Present() bool

Present determines whether a value has been set

func (*NullUint64) Scan

func (n *NullUint64) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullUint64) Set added in v1.1.0

func (n *NullUint64) Set(value uint64)

Set saves value into current struct

func (NullUint64) Typ

func (n NullUint64) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullUint64) UnmarshalJSON

func (n *NullUint64) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullUint64) V

func (n NullUint64) V() uint64

V returns value of underlying type if it was set, otherwise default value

func (NullUint64) Valid

func (n NullUint64) Valid() bool

Valid determines whether a value has been valid

func (NullUint64) Value

func (n NullUint64) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type NullUint8

type NullUint8 struct {
	P     *uint8
	Error error
}

NullUint8 represents a uint8 that may be null.

func Complex64Uint8

func Complex64Uint8(from complex64, defaultValue ...uint8) (nv NullUint8)

Complex64Uint8 convert value from complex64 to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func ComplexUint8

func ComplexUint8(from complex128, defaultValue ...uint8) (nv NullUint8)

ComplexUint8 convert value from complex128 to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func Float32Uint8

func Float32Uint8(from float32, defaultValue ...uint8) (nv NullUint8)

Float32Uint8 convert value from float32 to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func FloatUint8

func FloatUint8(from float64, defaultValue ...uint8) (nv NullUint8)

FloatUint8 convert value from float64 to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func IntUint8

func IntUint8(from int64, defaultValue ...uint8) (nv NullUint8)

IntUint8 convert value from int64 to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func NUint8

func NUint8(value uint8) NullUint8

NUint8 returns NullUint8 from uint8

func StringUint8

func StringUint8(from string, defaultValue ...uint8) (nv NullUint8)

StringUint8 convert value from string to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func Uint8

func Uint8(from uint64, defaultValue ...uint8) (nv NullUint8)

Uint8 convert value from uint64 to uint8. Returns value if type can safely converted, otherwise error & default value in result values

func (NullUint8) MarshalJSON

func (n NullUint8) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullUint8) Present

func (n NullUint8) Present() bool

Present determines whether a value has been set

func (*NullUint8) Scan

func (n *NullUint8) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullUint8) Set added in v1.1.0

func (n *NullUint8) Set(value uint8)

Set saves value into current struct

func (NullUint8) Typ

func (n NullUint8) Typ(options ...Option) *Type

Typ returns new instance with himself value. If current value is invalid, nil *Type returned

func (*NullUint8) UnmarshalJSON

func (n *NullUint8) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (NullUint8) V

func (n NullUint8) V() uint8

V returns value of underlying type if it was set, otherwise default value

func (NullUint8) Valid

func (n NullUint8) Valid() bool

Valid determines whether a value has been valid

func (NullUint8) Value

func (n NullUint8) Value() (driver.Value, error)

Value implements the sql driver Valuer interface.

type Option

type Option func(*opts) error

Option is interface function used as argument value for type conversion configuration

func Base

func Base(value int) Option

Base set base for int conversion. The base must be 2 <= base <= 36 for digit values >= 10.

func Delimiter

func Delimiter(value string) Option

Delimiter set delimiter for string manipulation

func FmtByte

func FmtByte(value byte) Option

FmtByte set format for float conversion. The format fmt is one of 'b' (-ddddp±ddd, a binary exponent), 'e' (-d.dddde±dd, a decimal exponent), 'E' (-d.ddddE±dd, a decimal exponent), 'f' (-ddd.dddd, no exponent), 'g' ('e' for large exponents, 'f' otherwise), or 'G' ('E' for large exponents, 'f' otherwise).

func Precision

func Precision(value int) Option

Precision set precision for float conversion. The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. For 'e', 'E', and 'f' it is the number of digits after the decimal point. For 'g' and 'G' it is the maximum number of significant digits (trailing zeros are removed). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.

func Prefix

func Prefix(value string) Option

Prefix set prefix for string manipulation

func Suffix

func Suffix(value string) Option

Suffix set suffix for string manipulation

type Type

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

Type stores all information about underlying value.

func NewType

func NewType(value interface{}, err error, options ...Option) *Type

NewType create a Type instance with value. This function recursive dereference value by a reference if value is a pointer

func Of

func Of(value interface{}, options ...Option) *Type

Of create type converter from interface value. This function recursive dereference value by a reference if value is a pointer

func (*Type) Bool

func (t *Type) Bool() (nv NullBool)

Bool convert interface value to bool. Returns true for any non-zero values

func (*Type) BoolHumanize

func (t *Type) BoolHumanize() (nv NullBool)

BoolHumanize convert interface value to bool. Returns false for string 'false' in case-insensitive mode or string equals '0', for other types returns true only for positive values

func (*Type) BoolPositive

func (t *Type) BoolPositive() (nv NullBool)

BoolPositive convert interface value to bool. Returns true only for positive values

func (*Type) Complex

func (t *Type) Complex(defaultValue ...complex128) (nv NullComplex)

Complex convert interface value to complex128 Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Complex64

func (t *Type) Complex64(defaultValue ...complex64) (nv NullComplex64)

Complex64 convert interface value to complex64. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Empty

func (t *Type) Empty() (nv NullBool)

Empty determine whether a variable is zero

func (*Type) Equals

func (t *Type) Equals(value interface{}) NullBool

Equals determine whether a variable is equals with current "value" (same value, but can have different primitives types) Primitives type is: int, uint, float, complex, bool

func (*Type) Error

func (t *Type) Error() error

Error returns Underlying error.

func (*Type) Float

func (t *Type) Float(defaultValue ...float64) (nv NullFloat)

Float convert interface value to float64. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Float32

func (t *Type) Float32(defaultValue ...float32) (nv NullFloat32)

Float32 convert interface value to float32. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Get

func (t *Type) Get(argIndexes ...interface{}) (typ *Type)

Get retrieve value from composite type, argument values used as index keys

func (*Type) Identical

func (t *Type) Identical(src interface{}) (nv NullBool)

Identical determine whether a variable is identical with current "value" (same type and same value)

func (*Type) Int

func (t *Type) Int(defaultValue ...int) (nv NullInt)

Int convert interface value to int. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Int16

func (t *Type) Int16(defaultValue ...int16) (nv NullInt16)

Int16 convert interface value to int16. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Int32

func (t *Type) Int32(defaultValue ...int32) (nv NullInt32)

Int32 convert interface value to int32. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Int64

func (t *Type) Int64(defaultValue ...int64) (nv NullInt64)

Int64 convert interface value to int64. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Int8

func (t *Type) Int8(defaultValue ...int8) (nv NullInt8)

Int8 convert interface value to int8. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Interface

func (t *Type) Interface() (nv NullInterface)

Interface returns value as interface. Returns nil if value can't safely represents as interface

func (*Type) IsBool

func (t *Type) IsBool(indirect ...bool) bool

IsBool determine whether a value is boolean type If indirect argument specified, real reflect type returned

func (*Type) IsComplex

func (t *Type) IsComplex(indirect ...bool) bool

IsComplex determine whether a value is complex type If indirect argument specified, real reflect type returned

func (*Type) IsComplex128

func (t *Type) IsComplex128(indirect ...bool) bool

IsComplex128 determine whether a value is complex128 type If indirect argument specified, real reflect type returned

func (*Type) IsComplex64

func (t *Type) IsComplex64(indirect ...bool) bool

IsComplex64 determine whether a value is complex64 type If indirect argument specified, real reflect type returned

func (*Type) IsComposite

func (t *Type) IsComposite(indirect ...bool) bool

IsComposite determine whether a value is composite type (array, slice, map) If indirect argument specified, real reflect type returned

func (*Type) IsFloat

func (t *Type) IsFloat(indirect ...bool) bool

IsFloat determine whether a value is float type If indirect argument specified, real reflect type returned

func (*Type) IsFloat32

func (t *Type) IsFloat32(indirect ...bool) bool

IsFloat32 determine whether a value is float32 type If indirect argument specified, real reflect type returned

func (*Type) IsFloat64

func (t *Type) IsFloat64(indirect ...bool) bool

IsFloat64 determine whether a value is float64 type If indirect argument specified, real reflect type returned

func (*Type) IsInt

func (t *Type) IsInt(indirect ...bool) bool

IsInt determine whether a value is signed integer type If indirect argument specified, real reflect type returned

func (*Type) IsNumeric

func (t *Type) IsNumeric(indirect ...bool) bool

IsNumeric determine whether a value is numeric type (int, uint, float, complex) If indirect argument specified, real reflect type returned

func (*Type) IsPointer

func (t *Type) IsPointer(indirect ...bool) bool

IsPointer determine whether a value is pointer type (Ptr, UnsafePointer, Uintptr) If indirect argument specified, real reflect type returned

func (*Type) IsPrimitives

func (t *Type) IsPrimitives(indirect ...bool) bool

IsPrimitives determine whether a value is primitives type (int, uint, float, complex, bool) If indirect argument specified, real reflect type returned

func (*Type) IsString

func (t *Type) IsString(indirect ...bool) bool

IsString determine whether a value is string type If indirect argument specified, real reflect type returned

func (*Type) IsUint

func (t *Type) IsUint(indirect ...bool) bool

IsUint determine whether a value is unsigned integer type If indirect argument specified, real reflect type returned

func (*Type) Kind

func (t *Type) Kind(indirect ...bool) reflect.Kind

Kind returns reflect type If indirect argument specified, real reflect type returned

func (*Type) OptionBase

func (t *Type) OptionBase() int

OptionBase returns the base for numeric conversion to string

func (*Type) OptionFmtByte

func (t *Type) OptionFmtByte() byte

OptionFmtByte returns float format option for float conversion to string

func (*Type) OptionPrecision

func (t *Type) OptionPrecision() int

OptionPrecision returns float precision for float conversion to string

func (*Type) String

func (t *Type) String() (nv NullString)

String convert interface value to string

func (*Type) StringBool

func (t *Type) StringBool() (nv NullString)

StringBool convert interface value to string represent as bool

func (*Type) StringComplex

func (t *Type) StringComplex(defaultValue ...complex64) (nv NullString)

StringComplex convert interface value to string represent as complex

func (*Type) StringDefault

func (t *Type) StringDefault(defaultValue string) (nv NullString)

StringDefault convert interface value to string with default value if it wasn't converted or it has zero value

func (*Type) StringEmpty

func (t *Type) StringEmpty() (nv NullString)

StringEmpty convert interface value to string and replace zero values to empty string if needed

func (*Type) StringFloat

func (t *Type) StringFloat(defaultValue ...float32) (nv NullString)

StringFloat convert interface value to string represent as float

func (*Type) StringInt

func (t *Type) StringInt() (nv NullString)

StringInt convert interface value to string represents as int

func (*Type) Uint

func (t *Type) Uint(defaultValue ...uint) (nv NullUint)

Uint convert interface value to uint. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Uint16

func (t *Type) Uint16(defaultValue ...uint16) (nv NullUint16)

Uint16 convert interface value to uint16. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Uint32

func (t *Type) Uint32(defaultValue ...uint32) (nv NullUint32)

Uint32 convert interface value to uint32. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Uint64

func (t *Type) Uint64(defaultValue ...uint64) (nv NullUint64)

Uint64 convert interface value to uint64. Returns value if type can safely converted, otherwise error & default value in result values

func (*Type) Uint8

func (t *Type) Uint8(defaultValue ...uint8) (nv NullUint8)

Uint8 convert interface value to uint8. Returns value if type can safely converted, otherwise error & default value in result values

type UintStringOption

type UintStringOption func(*uintStrOpts) error

UintStringOption is interface function used as argument value for type conversion configuration from uint to string

func UintStringBase

func UintStringBase(value int) UintStringOption

UintStringBase set base for uint conversion to string. The base must be 2 <= base <= 36 for digit values >= 10.

func UintStringDefault

func UintStringDefault(value string) UintStringOption

UintStringDefault set default string value for uint conversion to string.

Jump to

Keyboard shortcuts

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