Documentation ¶
Overview ¶
Package conv provides type conversion helpers.
- NewT converts T to *T.
- NewTFromS converts S to *T.
- ValueT converts *T to T, returns zero value in case of nil.
- MaybeT converts between protobuf WKT and optional value of corresponding Go type.
- MaybeTFromS converts optional S to optional T (optional usually means ref).
- Must* is panicking versions of above functions.
Index ¶
- func MaybeBool(wkt *wrapperspb.BoolValue) *bool
- func MaybeBoolFromNull(n sql.NullBool) *bool
- func MaybeDecimal(wkt *wrapperspb.StringValue) (*decimal.Decimal, error)
- func MaybeDecimalFromString(v *string) (*decimal.Decimal, error)
- func MaybeDuration(wkt *durationpb.Duration) *time.Duration
- func MaybeFloat32(wkt *wrapperspb.FloatValue) *float32
- func MaybeFloat64(wkt *wrapperspb.DoubleValue) *float64
- func MaybeFloat64FromNull(n sql.NullFloat64) *float64
- func MaybeInt16FromInt(v *int) (*int16, error)
- func MaybeInt16FromString(v *string) (*int16, error)
- func MaybeInt32(wkt *wrapperspb.Int32Value) *int32
- func MaybeInt32FromInt(v *int) (*int32, error)
- func MaybeInt32FromNull(n sql.NullInt32) *int32
- func MaybeInt32FromString(v *string) (*int32, error)
- func MaybeInt64(wkt *wrapperspb.Int64Value) *int64
- func MaybeInt64FromInt(v *int) *int64
- func MaybeInt64FromNull(n sql.NullInt64) *int64
- func MaybeInt64FromString(v *string) (*int64, error)
- func MaybeInt8FromInt(v *int) (*int8, error)
- func MaybeInt8FromString(v *string) (*int8, error)
- func MaybeIntFromInt16(v *int16) *int
- func MaybeIntFromInt32(v *int32) *int
- func MaybeIntFromInt64(v *int64) (*int, error)
- func MaybeIntFromInt8(v *int8) *int
- func MaybeIntFromString(v *string) (*int, error)
- func MaybeIntFromUInt16(v *uint16) *int
- func MaybeIntFromUInt32(v *uint32) (*int, error)
- func MaybeIntFromUInt64(v *uint64) (*int, error)
- func MaybeIntFromUInt8(v *uint8) *int
- func MaybeNullBool(v *bool) sql.NullBool
- func MaybeNullFloat64(v *float64) sql.NullFloat64
- func MaybeNullInt32(v *int32) sql.NullInt32
- func MaybeNullInt64(v *int64) sql.NullInt64
- func MaybeNullString(v *string) sql.NullString
- func MaybeNullTime(v time.Time) sql.NullTime
- func MaybePbBool(v *bool) *wrapperspb.BoolValue
- func MaybePbDouble(v *float64) *wrapperspb.DoubleValue
- func MaybePbDuration(v *time.Duration) *durationpb.Duration
- func MaybePbFloat(v *float32) *wrapperspb.FloatValue
- func MaybePbInt32(v *int32) *wrapperspb.Int32Value
- func MaybePbInt64(v *int64) *wrapperspb.Int64Value
- func MaybePbString(v *string) *wrapperspb.StringValue
- func MaybePbStringFromDecimal(d *decimal.Decimal) *wrapperspb.StringValue
- func MaybePbTimestamp(v time.Time) *timestamppb.Timestamp
- func MaybePbUInt32(v *uint32) *wrapperspb.UInt32Value
- func MaybePbUInt64(v *uint64) *wrapperspb.UInt64Value
- func MaybeString(wkt *wrapperspb.StringValue) *string
- func MaybeStringFromDecimal(d *decimal.Decimal) *string
- func MaybeStringFromInt(v *int) *string
- func MaybeStringFromInt16(v *int16) *string
- func MaybeStringFromInt32(v *int32) *string
- func MaybeStringFromInt64(v *int64) *string
- func MaybeStringFromInt8(v *int8) *string
- func MaybeStringFromNull(n sql.NullString) *string
- func MaybeTime(wkt *timestamppb.Timestamp) time.Time
- func MaybeTimeFromNull(n sql.NullTime) time.Time
- func MaybeTimeFromUnix(v *int64) (t time.Time)
- func MaybeTimeFromUnixMs(v *int64) (t time.Time)
- func MaybeTimeFromUnixNano(v *int64) (t time.Time)
- func MaybeUInt32(wkt *wrapperspb.UInt32Value) *uint32
- func MaybeUInt64(wkt *wrapperspb.UInt64Value) *uint64
- func MaybeUnixFromTime(t time.Time) *int64
- func MaybeUnixMsFromTime(t time.Time) *int64
- func MaybeUnixNanoFromTime(t time.Time) *int64
- func MustMaybeDecimalFromString(v *string) *decimal.Decimal
- func MustMaybeInt16FromInt(v *int) *int16
- func MustMaybeInt16FromString(v *string) *int16
- func MustMaybeInt32FromInt(v *int) *int32
- func MustMaybeInt32FromString(v *string) *int32
- func MustMaybeInt64FromString(v *string) *int64
- func MustMaybeInt8FromInt(v *int) *int8
- func MustMaybeInt8FromString(v *string) *int8
- func MustMaybeIntFromInt64(v *int64) *int
- func MustMaybeIntFromUInt32(v *uint32) *int
- func MustMaybeIntFromUInt64(v *uint64) *int
- func MustNewDecimal(v string) *decimal.Decimal
- func NewBool(v bool) *bool
- func NewDuration(v time.Duration) *time.Duration
- func NewFloat32(v float32) *float32
- func NewFloat64(v float64) *float64
- func NewInt(v int) *int
- func NewInt16(v int16) *int16
- func NewInt32(v int32) *int32
- func NewInt64(v int64) *int64
- func NewInt8(v int8) *int8
- func NewSensitiveString(v sensitive.String) *sensitive.String
- func NewString(v string) *string
- func NewUInt(v uint) *uint
- func NewUInt16(v uint16) *uint16
- func NewUInt32(v uint32) *uint32
- func NewUInt64(v uint64) *uint64
- func NewUInt8(v uint8) *uint8
- func TimeFromUnixMs(v int64) time.Time
- func UnixMsFromTime(v time.Time) int64
- func ValueBool(v *bool) bool
- func ValueDecimal(d *decimal.Decimal) decimal.Decimal
- func ValueDuration(v *time.Duration) time.Duration
- func ValueFloat32(v *float32) float32
- func ValueFloat64(v *float64) float64
- func ValueInt(v *int) int
- func ValueInt16(v *int16) int16
- func ValueInt32(v *int32) int32
- func ValueInt64(v *int64) int64
- func ValueInt8(v *int8) int8
- func ValueSensitiveString(v *sensitive.String) sensitive.String
- func ValueString(v *string) string
- func ValueUInt(v *uint) uint
- func ValueUInt16(v *uint16) uint16
- func ValueUInt32(v *uint32) uint32
- func ValueUInt64(v *uint64) uint64
- func ValueUInt8(v *uint8) uint8
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaybeBool ¶
func MaybeBool(wkt *wrapperspb.BoolValue) *bool
MaybeBool converts from protobuf WKT.
func MaybeBoolFromNull ¶ added in v0.6.0
MaybeBoolFromNull converts from sql Null.
func MaybeDecimal ¶
func MaybeDecimal(wkt *wrapperspb.StringValue) (*decimal.Decimal, error)
MaybeDecimal converts from protobuf WKT.
func MaybeDecimalFromString ¶ added in v0.2.0
MaybeDecimalFromString converts decimal.
func MaybeDuration ¶
func MaybeDuration(wkt *durationpb.Duration) *time.Duration
MaybeDuration converts from protobuf WKT.
func MaybeFloat32 ¶
func MaybeFloat32(wkt *wrapperspb.FloatValue) *float32
MaybeFloat32 converts from protobuf WKT.
func MaybeFloat64 ¶
func MaybeFloat64(wkt *wrapperspb.DoubleValue) *float64
MaybeFloat64 converts from protobuf WKT.
func MaybeFloat64FromNull ¶ added in v0.6.0
func MaybeFloat64FromNull(n sql.NullFloat64) *float64
MaybeFloat64FromNull converts from sql Null.
func MaybeInt16FromInt ¶ added in v0.5.0
MaybeInt16FromInt converts Go types or returns strconv.ErrRange.
func MaybeInt16FromString ¶ added in v0.5.0
MaybeInt16FromString converts Go types.
func MaybeInt32 ¶
func MaybeInt32(wkt *wrapperspb.Int32Value) *int32
MaybeInt32 converts from protobuf WKT.
func MaybeInt32FromInt ¶ added in v0.4.0
MaybeInt32FromInt converts Go types or returns strconv.ErrRange.
func MaybeInt32FromNull ¶ added in v0.6.0
MaybeInt32FromNull converts from sql Null.
func MaybeInt32FromString ¶ added in v0.5.0
MaybeInt32FromString converts Go types.
func MaybeInt64 ¶
func MaybeInt64(wkt *wrapperspb.Int64Value) *int64
MaybeInt64 converts from protobuf WKT.
func MaybeInt64FromInt ¶ added in v0.5.0
MaybeInt64FromInt converts Go types.
func MaybeInt64FromNull ¶ added in v0.6.0
MaybeInt64FromNull converts from sql Null.
func MaybeInt64FromString ¶ added in v0.5.0
MaybeInt64FromString converts Go types.
func MaybeInt8FromInt ¶ added in v0.5.0
MaybeInt8FromInt converts Go types or returns strconv.ErrRange.
func MaybeInt8FromString ¶ added in v0.5.0
MaybeInt8FromString converts Go types.
func MaybeIntFromInt16 ¶ added in v0.5.0
MaybeIntFromInt16 converts Go types.
func MaybeIntFromInt64 ¶ added in v0.5.0
MaybeIntFromInt64 converts Go types or returns strconv.ErrRange.
func MaybeIntFromInt8 ¶ added in v0.5.0
MaybeIntFromInt8 converts Go types.
func MaybeIntFromString ¶ added in v0.5.0
MaybeIntFromString converts Go types.
func MaybeIntFromUInt16 ¶ added in v0.5.0
MaybeIntFromUInt16 converts Go types.
func MaybeIntFromUInt32 ¶ added in v0.5.0
MaybeIntFromUInt32 converts Go types.
func MaybeIntFromUInt64 ¶ added in v0.5.0
MaybeIntFromUInt64 converts Go types.
func MaybeIntFromUInt8 ¶ added in v0.5.0
MaybeIntFromUInt8 converts Go types.
func MaybeNullBool ¶ added in v0.6.0
MaybeNullBool converts to sql Null.
func MaybeNullFloat64 ¶ added in v0.6.0
func MaybeNullFloat64(v *float64) sql.NullFloat64
MaybeNullFloat64 converts to sql Null.
func MaybeNullInt32 ¶ added in v0.6.0
MaybeNullInt32 converts to sql Null.
func MaybeNullInt64 ¶ added in v0.6.0
MaybeNullInt64 converts to sql Null.
func MaybeNullString ¶ added in v0.6.0
func MaybeNullString(v *string) sql.NullString
MaybeNullString converts to sql Null.
func MaybeNullTime ¶ added in v0.6.0
MaybeNullTime converts to sql Null.
func MaybePbBool ¶
func MaybePbBool(v *bool) *wrapperspb.BoolValue
MaybePbBool converts to protobuf WKT.
func MaybePbDouble ¶
func MaybePbDouble(v *float64) *wrapperspb.DoubleValue
MaybePbDouble converts to protobuf WKT.
func MaybePbDuration ¶
func MaybePbDuration(v *time.Duration) *durationpb.Duration
MaybePbDuration converts to protobuf WKT.
func MaybePbFloat ¶
func MaybePbFloat(v *float32) *wrapperspb.FloatValue
MaybePbFloat converts to protobuf WKT.
func MaybePbInt32 ¶
func MaybePbInt32(v *int32) *wrapperspb.Int32Value
MaybePbInt32 converts to protobuf WKT.
func MaybePbInt64 ¶
func MaybePbInt64(v *int64) *wrapperspb.Int64Value
MaybePbInt64 converts to protobuf WKT.
func MaybePbString ¶
func MaybePbString(v *string) *wrapperspb.StringValue
MaybePbString converts to protobuf WKT.
func MaybePbStringFromDecimal ¶
func MaybePbStringFromDecimal(d *decimal.Decimal) *wrapperspb.StringValue
MaybePbStringFromDecimal converts to protobuf WKT.
func MaybePbTimestamp ¶
func MaybePbTimestamp(v time.Time) *timestamppb.Timestamp
MaybePbTimestamp converts to protobuf WKT, returns nil for zero time.
func MaybePbUInt32 ¶ added in v0.6.0
func MaybePbUInt32(v *uint32) *wrapperspb.UInt32Value
MaybePbUInt32 converts to protobuf WKT.
func MaybePbUInt64 ¶ added in v0.6.0
func MaybePbUInt64(v *uint64) *wrapperspb.UInt64Value
MaybePbUInt64 converts to protobuf WKT.
func MaybeString ¶
func MaybeString(wkt *wrapperspb.StringValue) *string
MaybeString converts from protobuf WKT.
func MaybeStringFromDecimal ¶ added in v0.2.0
MaybeStringFromDecimal converts decimal.
func MaybeStringFromInt ¶
MaybeStringFromInt converts Go types.
func MaybeStringFromInt16 ¶ added in v0.5.0
MaybeStringFromInt16 converts Go types.
func MaybeStringFromInt32 ¶
MaybeStringFromInt32 converts Go types.
func MaybeStringFromInt64 ¶
MaybeStringFromInt64 converts Go types.
func MaybeStringFromInt8 ¶ added in v0.5.0
MaybeStringFromInt8 converts Go types.
func MaybeStringFromNull ¶ added in v0.6.0
func MaybeStringFromNull(n sql.NullString) *string
MaybeStringFromNull converts from sql Null.
func MaybeTime ¶
func MaybeTime(wkt *timestamppb.Timestamp) time.Time
MaybeTime converts from protobuf WKT, returns zero time for nil.
func MaybeTimeFromNull ¶ added in v0.6.0
MaybeTimeFromNull converts from sql Null.
func MaybeTimeFromUnix ¶ added in v0.5.0
MaybeTimeFromUnix converts seconds to time or nil to zero time.
func MaybeTimeFromUnixMs ¶ added in v0.5.0
MaybeTimeFromUnixMs converts milliseconds to time or nil to zero time.
func MaybeTimeFromUnixNano ¶ added in v0.5.0
MaybeTimeFromUnixNano converts nanoseconds to time or nil to zero time.
func MaybeUInt32 ¶
func MaybeUInt32(wkt *wrapperspb.UInt32Value) *uint32
MaybeUInt32 converts from protobuf WKT.
func MaybeUInt64 ¶
func MaybeUInt64(wkt *wrapperspb.UInt64Value) *uint64
MaybeUInt64 converts from protobuf WKT.
func MaybeUnixFromTime ¶
MaybeUnixFromTime converts time to seconds or nil for zero time.
func MaybeUnixMsFromTime ¶
MaybeUnixMsFromTime converts time to milliseconds or nil for zero time.
func MaybeUnixNanoFromTime ¶
MaybeUnixNanoFromTime converts time to nanoseconds or nil for zero time.
func MustMaybeDecimalFromString ¶ added in v0.2.0
MustMaybeDecimalFromString converts decimal or panics if v is not decimal.
func MustMaybeInt16FromInt ¶ added in v0.5.0
MustMaybeInt16FromInt converts Go types or panics on overflow.
func MustMaybeInt16FromString ¶ added in v0.5.0
MustMaybeInt16FromString converts Go types or panics on overflow/parse error.
func MustMaybeInt32FromInt ¶ added in v0.4.1
MustMaybeInt32FromInt converts Go types or panics on overflow.
func MustMaybeInt32FromString ¶ added in v0.5.0
MustMaybeInt32FromString converts Go types or panics on overflow/parse error.
func MustMaybeInt64FromString ¶ added in v0.5.0
MustMaybeInt64FromString converts Go types or panics on overflow/parse error.
func MustMaybeInt8FromInt ¶ added in v0.5.0
MustMaybeInt8FromInt converts Go types or panics on overflow.
func MustMaybeInt8FromString ¶ added in v0.5.0
MustMaybeInt8FromString converts Go types or panics on overflow/parse error.
func MustMaybeIntFromInt64 ¶
MustMaybeIntFromInt64 converts Go types or panics on overflow.
func MustMaybeIntFromUInt32 ¶ added in v0.5.0
MustMaybeIntFromUInt32 converts Go types or panics on overflow.
func MustMaybeIntFromUInt64 ¶ added in v0.5.0
MustMaybeIntFromUInt64 converts Go types or panics on overflow.
func MustNewDecimal ¶
MustNewDecimal returns ref to v or panics if v is not decimal.
func NewDuration ¶ added in v0.4.0
NewDuration returns ref to v.
func NewSensitiveString ¶
NewSensitiveString returns ref to v.
func TimeFromUnixMs ¶ added in v0.3.0
TimeFromUnixMs converts unix milliseconds to time. Returns zero time if v is 0 (instead of 1970-01-01).
func UnixMsFromTime ¶ added in v0.3.0
UnixMsFromTime converts time to unix milliseconds. Returns 0 both for zero time (instead of -6795364578871) and zero unixtime (1970-01-01).
func ValueDecimal ¶
ValueDecimal returns dereference of v or zero value if nil.
func ValueDuration ¶ added in v0.4.0
ValueDuration returns dereference of v or zero value if nil.
func ValueFloat32 ¶
ValueFloat32 returns dereference of v or zero value if nil.
func ValueFloat64 ¶
ValueFloat64 returns dereference of v or zero value if nil.
func ValueInt16 ¶
ValueInt16 returns dereference of v or zero value if nil.
func ValueInt32 ¶
ValueInt32 returns dereference of v or zero value if nil.
func ValueInt64 ¶
ValueInt64 returns dereference of v or zero value if nil.
func ValueSensitiveString ¶
ValueSensitiveString returns dereference of v or zero value if nil.
func ValueString ¶
ValueString returns dereference of v or zero value if nil.
func ValueUInt16 ¶
ValueUInt16 returns dereference of v or zero value if nil.
func ValueUInt32 ¶
ValueUInt32 returns dereference of v or zero value if nil.
func ValueUInt64 ¶
ValueUInt64 returns dereference of v or zero value if nil.
func ValueUInt8 ¶
ValueUInt8 returns dereference of v or zero value if nil.
Types ¶
This section is empty.