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 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 MaybeInt32(wkt *wrapperspb.Int32Value) *int32
- func MaybeInt64(wkt *wrapperspb.Int64Value) *int64
- func MaybeIntFromInt32(v *int32) *int
- 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 MaybeString(wkt *wrapperspb.StringValue) *string
- func MaybeStringFromDecimal(d *decimal.Decimal) *string
- func MaybeStringFromInt(v *int) *string
- func MaybeStringFromInt32(v *int32) *string
- func MaybeStringFromInt64(v *int64) *string
- func MaybeTime(wkt *timestamppb.Timestamp) time.Time
- func MaybeUInt32(wkt *wrapperspb.UInt32Value) *uint32
- func MaybeUInt32Value(v *uint32) *wrapperspb.UInt32Value
- func MaybeUInt64(wkt *wrapperspb.UInt64Value) *uint64
- func MaybeUInt64Value(v *uint64) *wrapperspb.UInt64Value
- 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 MustMaybeInt32FromInt(v *int) *int32
- func MustMaybeIntFromInt64(v *int64) *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 NewInt8(v int8) *int8
- func NewInt16(v int16) *int16
- func NewInt32(v int32) *int32
- func NewInt64(v int64) *int64
- func NewSensitiveString(v sensitive.String) *sensitive.String
- func NewString(v string) *string
- func NewUInt(v uint) *uint
- func NewUInt8(v uint8) *uint8
- func NewUInt16(v uint16) *uint16
- func NewUInt32(v uint32) *uint32
- func NewUInt64(v uint64) *uint64
- 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 ValueInt8(v *int8) int8
- func ValueInt16(v *int16) int16
- func ValueInt32(v *int32) int32
- func ValueInt64(v *int64) int64
- func ValueSensitiveString(v *sensitive.String) sensitive.String
- func ValueString(v *string) string
- func ValueUInt(v *uint) uint
- func ValueUInt8(v *uint8) uint8
- func ValueUInt16(v *uint16) uint16
- func ValueUInt32(v *uint32) uint32
- func ValueUInt64(v *uint64) uint64
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 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 MaybeInt32 ¶
func MaybeInt32(wkt *wrapperspb.Int32Value) *int32
MaybeInt32 converts from protobuf WKT.
func MaybeInt64 ¶
func MaybeInt64(wkt *wrapperspb.Int64Value) *int64
MaybeInt64 converts from protobuf WKT.
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 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 MaybeStringFromInt32 ¶
MaybeStringFromInt32 converts Go types.
func MaybeStringFromInt64 ¶
MaybeStringFromInt64 converts Go types.
func MaybeTime ¶
func MaybeTime(wkt *timestamppb.Timestamp) time.Time
MaybeTime converts from protobuf WKT, returns zero time for nil.
func MaybeUInt32 ¶
func MaybeUInt32(wkt *wrapperspb.UInt32Value) *uint32
MaybeUInt32 converts from protobuf WKT.
func MaybeUInt32Value ¶
func MaybeUInt32Value(v *uint32) *wrapperspb.UInt32Value
MaybeUInt32Value converts to protobuf WKT.
func MaybeUInt64 ¶
func MaybeUInt64(wkt *wrapperspb.UInt64Value) *uint64
MaybeUInt64 converts from protobuf WKT.
func MaybeUInt64Value ¶
func MaybeUInt64Value(v *uint64) *wrapperspb.UInt64Value
MaybeUInt64Value converts to 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.
func MustMaybeInt32FromInt ¶ added in v0.4.1
MustMaybeInt32FromInt converts Go types or panics on overflows.
func MustMaybeIntFromInt64 ¶
MustMaybeIntFromInt64 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 ValueUInt8 ¶
ValueUInt8 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.
Types ¶
This section is empty.