conv

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 8 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 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 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 MaybeIntFromInt32

func MaybeIntFromInt32(v *int32) *int

MaybeIntFromInt32 converts Go types.

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

func MaybeStringFromDecimal(d *decimal.Decimal) *string

MaybeStringFromDecimal converts decimal.

func MaybeStringFromInt

func MaybeStringFromInt(v *int) *string

MaybeStringFromInt 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 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

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.

func MustMaybeIntFromInt64

func MustMaybeIntFromInt64(v *int64) *int

MustMaybeIntFromInt64 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 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 NewInt8

func NewInt8(v int8) *int8

NewInt8 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 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 NewUInt8

func NewUInt8(v uint8) *uint8

NewUInt8 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 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 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 ValueInt8

func ValueInt8(v *int8) int8

ValueInt8 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 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 ValueUInt8

func ValueUInt8(v *uint8) uint8

ValueUInt8 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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