conv

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 9 Imported by: 0

README

Convert types for Go

PkgGoDev Go Report Card Release

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

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

func MaybeBoolFromNull(n sql.NullBool) *bool

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

func MaybeDecimalFromString(v *string) (*decimal.Decimal, error)

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

func MaybeInt16FromInt(v *int) (*int16, error)

MaybeInt16FromInt converts Go types or returns strconv.ErrRange.

func MaybeInt16FromString added in v0.5.0

func MaybeInt16FromString(v *string) (*int16, error)

MaybeInt16FromString converts Go types.

func MaybeInt32

func MaybeInt32(wkt *wrapperspb.Int32Value) *int32

MaybeInt32 converts from protobuf WKT.

func MaybeInt32FromInt added in v0.4.0

func MaybeInt32FromInt(v *int) (*int32, error)

MaybeInt32FromInt converts Go types or returns strconv.ErrRange.

func MaybeInt32FromNull added in v0.6.0

func MaybeInt32FromNull(n sql.NullInt32) *int32

MaybeInt32FromNull converts from sql Null.

func MaybeInt32FromString added in v0.5.0

func MaybeInt32FromString(v *string) (*int32, error)

MaybeInt32FromString converts Go types.

func MaybeInt64

func MaybeInt64(wkt *wrapperspb.Int64Value) *int64

MaybeInt64 converts from protobuf WKT.

func MaybeInt64FromInt added in v0.5.0

func MaybeInt64FromInt(v *int) *int64

MaybeInt64FromInt converts Go types.

func MaybeInt64FromNull added in v0.6.0

func MaybeInt64FromNull(n sql.NullInt64) *int64

MaybeInt64FromNull converts from sql Null.

func MaybeInt64FromString added in v0.5.0

func MaybeInt64FromString(v *string) (*int64, error)

MaybeInt64FromString converts Go types.

func MaybeInt8FromInt added in v0.5.0

func MaybeInt8FromInt(v *int) (*int8, error)

MaybeInt8FromInt converts Go types or returns strconv.ErrRange.

func MaybeInt8FromString added in v0.5.0

func MaybeInt8FromString(v *string) (*int8, error)

MaybeInt8FromString converts Go types.

func MaybeIntFromInt16 added in v0.5.0

func MaybeIntFromInt16(v *int16) *int

MaybeIntFromInt16 converts Go types.

func MaybeIntFromInt32

func MaybeIntFromInt32(v *int32) *int

MaybeIntFromInt32 converts Go types.

func MaybeIntFromInt64 added in v0.5.0

func MaybeIntFromInt64(v *int64) (*int, error)

MaybeIntFromInt64 converts Go types or returns strconv.ErrRange.

func MaybeIntFromInt8 added in v0.5.0

func MaybeIntFromInt8(v *int8) *int

MaybeIntFromInt8 converts Go types.

func MaybeIntFromString added in v0.5.0

func MaybeIntFromString(v *string) (*int, error)

MaybeIntFromString converts Go types.

func MaybeIntFromUInt16 added in v0.5.0

func MaybeIntFromUInt16(v *uint16) *int

MaybeIntFromUInt16 converts Go types.

func MaybeIntFromUInt32 added in v0.5.0

func MaybeIntFromUInt32(v *uint32) (*int, error)

MaybeIntFromUInt32 converts Go types.

func MaybeIntFromUInt64 added in v0.5.0

func MaybeIntFromUInt64(v *uint64) (*int, error)

MaybeIntFromUInt64 converts Go types.

func MaybeIntFromUInt8 added in v0.5.0

func MaybeIntFromUInt8(v *uint8) *int

MaybeIntFromUInt8 converts Go types.

func MaybeNullBool added in v0.6.0

func MaybeNullBool(v *bool) sql.NullBool

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

func MaybeNullInt32(v *int32) sql.NullInt32

MaybeNullInt32 converts to sql Null.

func MaybeNullInt64 added in v0.6.0

func MaybeNullInt64(v *int64) sql.NullInt64

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

func MaybeNullTime(v time.Time) sql.NullTime

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

func MaybeStringFromDecimal(d *decimal.Decimal) *string

MaybeStringFromDecimal converts decimal.

func MaybeStringFromInt

func MaybeStringFromInt(v *int) *string

MaybeStringFromInt converts Go types.

func MaybeStringFromInt16 added in v0.5.0

func MaybeStringFromInt16(v *int16) *string

MaybeStringFromInt16 converts Go types.

func MaybeStringFromInt32

func MaybeStringFromInt32(v *int32) *string

MaybeStringFromInt32 converts Go types.

func MaybeStringFromInt64

func MaybeStringFromInt64(v *int64) *string

MaybeStringFromInt64 converts Go types.

func MaybeStringFromInt8 added in v0.5.0

func MaybeStringFromInt8(v *int8) *string

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

func MaybeTimeFromNull(n sql.NullTime) time.Time

MaybeTimeFromNull converts from sql Null.

func MaybeTimeFromUnix added in v0.5.0

func MaybeTimeFromUnix(v *int64) (t time.Time)

MaybeTimeFromUnix converts seconds to time or nil to zero time.

func MaybeTimeFromUnixMs added in v0.5.0

func MaybeTimeFromUnixMs(v *int64) (t time.Time)

MaybeTimeFromUnixMs converts milliseconds to time or nil to zero time.

func MaybeTimeFromUnixNano added in v0.5.0

func MaybeTimeFromUnixNano(v *int64) (t time.Time)

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

func MaybeUnixFromTime(t time.Time) *int64

MaybeUnixFromTime converts time to seconds or nil for zero time.

func MaybeUnixMsFromTime

func MaybeUnixMsFromTime(t time.Time) *int64

MaybeUnixMsFromTime converts time to milliseconds or nil for zero time.

func MaybeUnixNanoFromTime

func MaybeUnixNanoFromTime(t time.Time) *int64

MaybeUnixNanoFromTime converts time to nanoseconds or nil for zero time.

func MustMaybeDecimalFromString added in v0.2.0

func MustMaybeDecimalFromString(v *string) *decimal.Decimal

MustMaybeDecimalFromString converts decimal or panics if v is not decimal.

func MustMaybeInt16FromInt added in v0.5.0

func MustMaybeInt16FromInt(v *int) *int16

MustMaybeInt16FromInt converts Go types or panics on overflow.

func MustMaybeInt16FromString added in v0.5.0

func MustMaybeInt16FromString(v *string) *int16

MustMaybeInt16FromString converts Go types or panics on overflow/parse error.

func MustMaybeInt32FromInt added in v0.4.1

func MustMaybeInt32FromInt(v *int) *int32

MustMaybeInt32FromInt converts Go types or panics on overflow.

func MustMaybeInt32FromString added in v0.5.0

func MustMaybeInt32FromString(v *string) *int32

MustMaybeInt32FromString converts Go types or panics on overflow/parse error.

func MustMaybeInt64FromString added in v0.5.0

func MustMaybeInt64FromString(v *string) *int64

MustMaybeInt64FromString converts Go types or panics on overflow/parse error.

func MustMaybeInt8FromInt added in v0.5.0

func MustMaybeInt8FromInt(v *int) *int8

MustMaybeInt8FromInt converts Go types or panics on overflow.

func MustMaybeInt8FromString added in v0.5.0

func MustMaybeInt8FromString(v *string) *int8

MustMaybeInt8FromString converts Go types or panics on overflow/parse error.

func MustMaybeIntFromInt64

func MustMaybeIntFromInt64(v *int64) *int

MustMaybeIntFromInt64 converts Go types or panics on overflow.

func MustMaybeIntFromUInt32 added in v0.5.0

func MustMaybeIntFromUInt32(v *uint32) *int

MustMaybeIntFromUInt32 converts Go types or panics on overflow.

func MustMaybeIntFromUInt64 added in v0.5.0

func MustMaybeIntFromUInt64(v *uint64) *int

MustMaybeIntFromUInt64 converts Go types or panics on overflow.

func MustNewDecimal

func MustNewDecimal(v string) *decimal.Decimal

MustNewDecimal returns ref to v or panics if v is not decimal.

func NewBool

func NewBool(v bool) *bool

NewBool returns ref to v.

func NewDuration added in v0.4.0

func NewDuration(v time.Duration) *time.Duration

NewDuration returns ref to v.

func NewFloat32

func NewFloat32(v float32) *float32

NewFloat32 returns ref to v.

func NewFloat64

func NewFloat64(v float64) *float64

NewFloat64 returns ref to v.

func NewInt

func NewInt(v int) *int

NewInt returns ref to v.

func NewInt16

func NewInt16(v int16) *int16

NewInt16 returns ref to v.

func NewInt32

func NewInt32(v int32) *int32

NewInt32 returns ref to v.

func NewInt64

func NewInt64(v int64) *int64

NewInt64 returns ref to v.

func NewInt8

func NewInt8(v int8) *int8

NewInt8 returns ref to v.

func NewSensitiveString

func NewSensitiveString(v sensitive.String) *sensitive.String

NewSensitiveString returns ref to v.

func NewString

func NewString(v string) *string

NewString returns ref to v.

func NewUInt

func NewUInt(v uint) *uint

NewUInt returns ref to v.

func NewUInt16

func NewUInt16(v uint16) *uint16

NewUInt16 returns ref to v.

func NewUInt32

func NewUInt32(v uint32) *uint32

NewUInt32 returns ref to v.

func NewUInt64

func NewUInt64(v uint64) *uint64

NewUInt64 returns ref to v.

func NewUInt8

func NewUInt8(v uint8) *uint8

NewUInt8 returns ref to v.

func TimeFromUnixMs added in v0.3.0

func TimeFromUnixMs(v int64) time.Time

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

func UnixMsFromTime(v time.Time) int64

UnixMsFromTime converts time to unix milliseconds. Returns 0 both for zero time (instead of -6795364578871) and zero unixtime (1970-01-01).

func ValueBool

func ValueBool(v *bool) bool

ValueBool returns dereference of v or zero value if nil.

func ValueDecimal

func ValueDecimal(d *decimal.Decimal) decimal.Decimal

ValueDecimal returns dereference of v or zero value if nil.

func ValueDuration added in v0.4.0

func ValueDuration(v *time.Duration) time.Duration

ValueDuration returns dereference of v or zero value if nil.

func ValueFloat32

func ValueFloat32(v *float32) float32

ValueFloat32 returns dereference of v or zero value if nil.

func ValueFloat64

func ValueFloat64(v *float64) float64

ValueFloat64 returns dereference of v or zero value if nil.

func ValueInt

func ValueInt(v *int) int

ValueInt returns dereference of v or zero value if nil.

func ValueInt16

func ValueInt16(v *int16) int16

ValueInt16 returns dereference of v or zero value if nil.

func ValueInt32

func ValueInt32(v *int32) int32

ValueInt32 returns dereference of v or zero value if nil.

func ValueInt64

func ValueInt64(v *int64) int64

ValueInt64 returns dereference of v or zero value if nil.

func ValueInt8

func ValueInt8(v *int8) int8

ValueInt8 returns dereference of v or zero value if nil.

func ValueSensitiveString

func ValueSensitiveString(v *sensitive.String) sensitive.String

ValueSensitiveString returns dereference of v or zero value if nil.

func ValueString

func ValueString(v *string) string

ValueString returns dereference of v or zero value if nil.

func ValueUInt

func ValueUInt(v *uint) uint

ValueUInt returns dereference of v or zero value if nil.

func ValueUInt16

func ValueUInt16(v *uint16) uint16

ValueUInt16 returns dereference of v or zero value if nil.

func ValueUInt32

func ValueUInt32(v *uint32) uint32

ValueUInt32 returns dereference of v or zero value if nil.

func ValueUInt64

func ValueUInt64(v *uint64) uint64

ValueUInt64 returns dereference of v or zero value if nil.

func ValueUInt8

func ValueUInt8(v *uint8) uint8

ValueUInt8 returns dereference of v or zero value if nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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