conv

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueIsNull        = errors.New("value is nil")
	ErrValueIsUnknown     = errors.New("value is unknown")
	ErrValueIsEmpty       = errors.New("value is empty")
	ErrValueTypeUnhandled = errors.New("value type is unhandled, this usually means this package is out of date with the upstream provider framework")
)
View Source
var FloatPrecision uint = 3

Functions

func AttributeValueLength

func AttributeValueLength(v attr.Value) int

AttributeValueLength attempts to determine the "length" of an attribute value, for types where that value has significance.

func AttributeValueToBigFloat

func AttributeValueToBigFloat(v attr.Value) (*big.Float, error)

AttributeValueToBigFloat accepts either a literal or pointer to a concrete attr.Value implementation, attempting to return a *big.Float instance of its value.

func AttributeValueToFloat64

func AttributeValueToFloat64(v attr.Value) (float64, big.Accuracy, error)

AttributeValueToFloat64 accepts either a literal or pointer to a concrete attr.Value implementation, attempting to to return a float64 representation of its value.

func AttributeValueToInt64

func AttributeValueToInt64(v attr.Value) (int64, big.Accuracy, error)

AttributeValueToInt64 accepts either a literal or pointer to a concrete attr.Value implementation, attempting to return an int64 representation of its value.

func AttributeValueToString

func AttributeValueToString(v attr.Value) string

AttributeValueToString will attempt to execute the appropriate AttributeStringerFunc from the ones registered.

func AttributeValueToStrings added in v1.0.0

func AttributeValueToStrings(av attr.Value) []string

AttributeValueToStrings attempts to convert the provided attr.Value into a slice of strings.

func BoolToBoolValue

func BoolToBoolValue(b bool) types.Bool

BoolToBoolValue takes a bool and wraps it up as a types.Bool

func BoolValueToBool

func BoolValueToBool(v attr.Value) bool

BoolValueToBool accepts either a types.Bool or *types.Bool and extracts the raw bool value within

func BoolValueToBoolPtr

func BoolValueToBoolPtr(v attr.Value) *bool

BoolValueToBoolPtr accepts either a types.Bool or *types.Bool, extracting the raw bool value within and returning a pointer to a copy of that value

If the Value is unknown or null, a nil is returned.

func BoolValueToString

func BoolValueToString(v attr.Value) string

BoolValueToString accepts an instance of either types.Bool or *types.Bool, attempting to convert the value to a string.

func BytesToStringValue added in v0.1.2

func BytesToStringValue(b []byte) types.String

BytesToStringValue takes a byte slice and wraps it as a types.String. If the provided slice is `nil`, then the resulting String type will be marked as "null".

func Float32ToFloat64Value

func Float32ToFloat64Value(f float32) types.Float64

Float32ToFloat64Value takes a float32 and wraps it up as a types.Float64

func Float32ToNumberValue

func Float32ToNumberValue(f float32) types.Number

Float32ToNumberValue takes a float32 and wraps it up as a types.Number

func Float64ToFloat64Value

func Float64ToFloat64Value(f float64) types.Float64

Float64ToFloat64Value takes a float64 and wraps it up as a types.Float64

func Float64ToNumberValue

func Float64ToNumberValue(f float64) types.Number

Float64ToNumberValue takes a float64 and wraps it up as a types.Number

func Float64ValueToFloat32

func Float64ValueToFloat32(v attr.Value) float32

Float64ValueToFloat32 accepts either a types.Float64 or *types.Float64, returning a float32 representation of the raw float64 value

func Float64ValueToFloat64

func Float64ValueToFloat64(v attr.Value) float64

Float64ValueToFloat64 accepts either a types.Float64 or *types.Float64, returning the raw float64 value within

func Float64ValueToString

func Float64ValueToString(v attr.Value) string

Float64ValueToString accepts an instance of either types.Float64 or *types.Float64, attempting to convert the value to a string.

func FormatAttributePathSteps

func FormatAttributePathSteps(pathSteps ...tftypes.AttributePathStep) string

FormatAttributePathSteps takes one or more path steps and joins them together with "."

func FormatAttributePaths

func FormatAttributePaths(paths ...*tftypes.AttributePath) string

FormatAttributePaths takes one or more *tftypes.AttributePaths and returns a pretty-printable string.

func GoNumberToString

func GoNumberToString(num interface{}) string

GoNumberToString is a laziness helper to convert several types to a usable string value.

func Int64ListToInts

func Int64ListToInts(v attr.Value) []int

Int64ListToInts accepts an instance of either types.List or *types.List where ElemType MUST be types.Int64Type, returning a slice of ints of the value of each element.

func Int64SetToInts

func Int64SetToInts(v attr.Value) []int

Int64SetToInts accepts an instance of either types.Set or *types.set where ElemType MUST be types.Int64Type returning a slice of ints of the value of each element

func Int64ToInt64Value

func Int64ToInt64Value(i int64) types.Int64

Int64ToInt64Value takes an int64 and wraps it up as a types.Int64

func Int64ToNumberValue

func Int64ToNumberValue(i int64) types.Number

Int64ToNumberValue takes an int64 and wraps it up as a types.Number

func Int64ValueToInt

func Int64ValueToInt(v attr.Value) int

Int64ValueToInt accepts either a types.Int64 or *types.Int64, returning an int representation of the value within

func Int64ValueToInt64

func Int64ValueToInt64(v attr.Value) int64

Int64ValueToInt64 accepts either a types.Int64 or *types.Int64, returning the raw int64 value within

func Int64ValueToIntPtr

func Int64ValueToIntPtr(v attr.Value) *int

Int64ValueToIntPtr accepts either a types.Int64 or *types.Int64, returning a pointer to a copy of the int representation of the value within

If the Value is unknown or null, a nil is returned.

func Int64ValueToString

func Int64ValueToString(v attr.Value) string

Int64ValueToString accepts an instance of either types.Int64 or *types.Int64, attempting to convert the value to a string.

func IntPtrToInt64Value

func IntPtrToInt64Value(i *int) types.Int64

IntPtrToInt64Value takes an *int and wraps it up as a types.Int64

If the go value is nil, Null will be true on the outgoing attr.Value type

func IntToInt64Value

func IntToInt64Value(i int) types.Int64

IntToInt64Value takes an int and wraps it up as a types.Int64

func IntToNumberValue

func IntToNumberValue(i int) types.Number

IntToNumberValue takes an int and wraps it up as a types.Number

func IntsToInt64List

func IntsToInt64List(in []int, nullOnEmpty bool) types.List

IntsToInt64List takes a slice of ints and creates a typed types.List with a ElemType of types.Int64Type and each value of Elems being an instance of types.Int64

If nullOnEmpty parameter is `true`, sets the Null field on the returned types.List to `true`. This can be used to avoid Terraform state inconsistencies under certain circumstances.

func IntsToInt64Set

func IntsToInt64Set(in []int, nullOnEmpty bool) types.Set

IntsToInt64Set takes a slice of ints and creates a typed types.Set with an ElemType of types.Int64Type and each value of Elems being an instance of types.Int64

If nullOnEmpty parameter is `true`, sets the Null field on the returned types.Set to `true`. This can be used to avoid Terraform state inconsistencies under certain circumstances.

func IsValueIsEmptyError

func IsValueIsEmptyError(err error) bool

func IsValueIsNullError

func IsValueIsNullError(err error) bool

func IsValueIsUnknownError

func IsValueIsUnknownError(err error) bool

func IsValueTypeUnhandledError added in v1.0.0

func IsValueTypeUnhandledError(err error) bool

func LengthOfListValue

func LengthOfListValue(v attr.Value) int

LengthOfListValue returns the number of elements in the List attribute. This will return 0 if the attribute was not set, set to null, or defined as an empty list.

func LengthOfMapValue

func LengthOfMapValue(v attr.Value) int

LengthOfMapValue returns the number of elements in the Map attribute. This will return 0 if the attribute was not set, set to null, or defined as an empty map.

func LengthOfSetValue

func LengthOfSetValue(v attr.Value) int

LengthOfSetValue returns the number of elements in the Set attribute. This will return 0 if the attribute was not set, set to null, or defined as an empty set.

func LengthOfStringValue

func LengthOfStringValue(v attr.Value) int

LengthOfStringValue returns the number of bytes in the String attribute. This will return 0 if the attribute was not set, set to 0, or defined as an empty string.

func NumberListToInts added in v1.0.0

func NumberListToInts(v attr.Value) []int

NumberListToInts accepts either an instance of types.List or *types.List where ElemType MUST be types.NumberType returning a slice of ints of the value of each element

func NumberSetToInts added in v1.0.0

func NumberSetToInts(v attr.Value) []int

NumberSetToInts accepts either an instance of types.Set or *types.Set where ElemType MUST be types.NumberType returning a slice of ints of the value of each element

func NumberValueToBigFloat

func NumberValueToBigFloat(v attr.Value) *big.Float

NumberValueToBigFloat accepts either a types.Number or *types.Number, returning the raw *big.Float value. This may be nil if the value was not set.

func NumberValueToFloat64

func NumberValueToFloat64(v attr.Value) (float64, big.Accuracy)

NumberValueToFloat64 accepts either a types.Number or *types.Number, returning a float64 representation of the *big.Float value within. It will return [0.0, big.Exact] of the value was not set.

func NumberValueToInt added in v1.0.0

func NumberValueToInt(v attr.Value) (int, big.Accuracy)

NumberValueToInt accepts either a types.Number or *types.Number, returning an int representation of the *big.Float value within. It will return [0, big.Exact] if the value was not set

func NumberValueToInt64

func NumberValueToInt64(v attr.Value) (int64, big.Accuracy)

NumberValueToInt64 accepts either a types.Number or *types.Number, returning an int64 representation of the *big.Float value within. It will return [0, big.Exact] of the value was not set.

func NumberValueToString

func NumberValueToString(v attr.Value) string

NumberValueToString accepts an instance of either types.Number or *types.Number, attempting to convert the value to a string.

func StringListToStrings added in v1.0.0

func StringListToStrings(v attr.Value) []string

StringListToStrings accepts an instance of either types.List or *types.List where ElemType MUST be types.StringType, returning a slice of strings of the value of each element

func StringPtrToStringValue

func StringPtrToStringValue(s *string) types.String

StringPtrToStringValue takes a *string and wraps it up as a types.String If the go value is nil, Null will be true on the outgoing attr.Value type

func StringSetToStrings added in v1.0.0

func StringSetToStrings(v attr.Value) []string

StringSetToStrings accepts an instance of either types.Set or *types.Set where ElemType MUST be types.StringType, returning a slice of strings of the value of each element

func StringToStringValue

func StringToStringValue(s string) types.String

StringToStringValue takes a string and wraps it up as a types.String

func StringValueToBytes

func StringValueToBytes(v attr.Value) []byte

StringValueToBytes accepts an instance of either types.String or *types.String, returning the raw string value cast to a byte slice

func StringValueToFloat64

func StringValueToFloat64(v attr.Value) (float64, error)

StringValueToFloat64 accepts either a types.String or *types.string, attempting to parse the value as a float64

func StringValueToInt64

func StringValueToInt64(v attr.Value) (int, error)

StringValueToInt64 accepts either a types.String or *types.String, attempting to parse the value as an int64.

func StringValueToString

func StringValueToString(v attr.Value) string

StringValueToString accepts an instance of either types.String or *types.String, returning the raw string value

func StringValueToStringPtr

func StringValueToStringPtr(v attr.Value) *string

StringValueToStringPtr accepts an instance of either types.String or *types.String, returning a pointer to a copy of the raw string value

If the Value is unknown or null, a nil is returned.

func TestAttributeValueState

func TestAttributeValueState(av attr.Value) error

TestAttributeValueState - Determine the state of the attribute value

An Attribute Value can have one of 3 main states:

  1. Unknown
  2. Null
  3. Valued

This function tests every attr.Value implementation for each of these states, and additionally performs an "emptiness" check.

There are bespoke errors for Unknown, Null, and Empty. See errors.go for details on how to use these error types.

This function will only ever return one error, going from greatest to least significance:

unknown > null > empty > non-empty

A 'nil' response from this function means the attribute's value was defined to a non-"empty" value at runtime. See function body for a particular type if you're interested in what "empty" means.

func ValueToBoolType

func ValueToBoolType(v attr.Value) types.Bool

ValueToBoolType ensures we have a types.Bool literal

func ValueToFloat64Type

func ValueToFloat64Type(v attr.Value) types.Float64

ValueToFloat64Type ensures we have a types.Float64 literal

func ValueToInt64Type

func ValueToInt64Type(v attr.Value) types.Int64

ValueToInt64Type ensures we have a types.Int64 literal

func ValueToListType

func ValueToListType(v attr.Value) types.List

ValueToListType ensures we have a types.List literal

func ValueToMapType

func ValueToMapType(v attr.Value) types.Map

ValueToMapType ensures we have a types.Map literal

func ValueToNumberType

func ValueToNumberType(v attr.Value) types.Number

ValueToNumberType ensures we have a types.Number literal

func ValueToObjectType

func ValueToObjectType(v attr.Value) types.Object

ValueToObjectType ensures we have a types.Object literal

func ValueToSetType

func ValueToSetType(v attr.Value) types.Set

ValueToSetType ensures we have a types.Set literal

func ValueToStringType

func ValueToStringType(v attr.Value) types.String

ValueToStringType ensures we have a types.String literal

func ValueTypeUnhandledError added in v1.0.0

func ValueTypeUnhandledError(scope string, av attr.Value) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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