reflect
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package reflect contains the implementation for converting framework-defineddata into and from provider-defined Go types.
Index¶
- func BuildValue(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func FromAttributeValue(ctx context.Context, typ attr.Type, val attr.Value, path path.Path) (attr.Value, diag.Diagnostics)
- func FromBigFloat(ctx context.Context, typ attr.Type, val *big.Float, path path.Path) (attr.Value, diag.Diagnostics)
- func FromBigInt(ctx context.Context, typ attr.Type, val *big.Int, path path.Path) (attr.Value, diag.Diagnostics)
- func FromBool(ctx context.Context, typ attr.Type, val bool, path path.Path) (attr.Value, diag.Diagnostics)
- func FromFloat(ctx context.Context, typ attr.Type, val float64, path path.Path) (attr.Value, diag.Diagnostics)
- func FromInt(ctx context.Context, typ attr.Type, val int64, path path.Path) (attr.Value, diag.Diagnostics)
- func FromMap(ctx context.Context, typ attr.TypeWithElementType, val reflect.Value, ...) (attr.Value, diag.Diagnostics)
- func FromNullable(ctx context.Context, typ attr.Type, val Nullable, path path.Path) (attr.Value, diag.Diagnostics)
- func FromPointer(ctx context.Context, typ attr.Type, value reflect.Value, path path.Path) (attr.Value, diag.Diagnostics)
- func FromSlice(ctx context.Context, typ attr.Type, val reflect.Value, path path.Path) (attr.Value, diag.Diagnostics)
- func FromString(ctx context.Context, typ attr.Type, val string, path path.Path) (attr.Value, diag.Diagnostics)
- func FromStruct(ctx context.Context, typ attr.TypeWithAttributeTypes, val reflect.Value, ...) (attr.Value, diag.Diagnostics)
- func FromUint(ctx context.Context, typ attr.Type, val uint64, path path.Path) (attr.Value, diag.Diagnostics)
- func FromUnknownable(ctx context.Context, typ attr.Type, val Unknownable, path path.Path) (attr.Value, diag.Diagnostics)
- func FromValue(ctx context.Context, typ attr.Type, val interface{}, path path.Path) (attr.Value, diag.Diagnostics)
- func FromValueCreator(ctx context.Context, typ attr.Type, val tftypes.ValueCreator, path path.Path) (attr.Value, diag.Diagnostics)
- func Into(ctx context.Context, typ attr.Type, val tftypes.Value, target interface{}, ...) diag.Diagnostics
- func IsGenericAttrValue(ctx context.Context, target interface{}) bool
- func Map(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func NewAttributeValue(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func NewNullable(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func NewUnknownable(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func NewValueConverter(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func Number(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func Pointer(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func Primitive(ctx context.Context, typ attr.Type, val tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- func Struct(ctx context.Context, typ attr.Type, object tftypes.Value, target reflect.Value, ...) (reflect.Value, diag.Diagnostics)
- type DiagIntoIncompatibleType
- type DiagNewAttributeValueIntoWrongType
- type Nullable
- type Options
- type Unknownable
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcBuildValue¶
func BuildValue(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
BuildValue constructs a reflect.Value of the same type as `target`,populated with the data in `val`. It will defensively instantiate new valuesto set, making it safe for use with pointer types which may be nil. It triesto give consumers the ability to override its default behaviors whereverpossible.
funcFromAttributeValue¶
func FromAttributeValue(ctxcontext.Context, typattr.Type, valattr.Value, pathpath.Path) (attr.Value,diag.Diagnostics)
FromAttributeValue creates an attr.Value from an attr.Value. It just returnsthe attr.Value it is passed or an error if there is an unexpected mismatchbetween the attr.Type and attr.Value.
It is meant to be called through FromValue, not directly.
funcFromBigFloat¶
func FromBigFloat(ctxcontext.Context, typattr.Type, val *big.Float, pathpath.Path) (attr.Value,diag.Diagnostics)
FromBigFloat creates an attr.Value using `typ` from a *big.Float.
It is meant to be called through FromValue, not directly.
funcFromBigInt¶
func FromBigInt(ctxcontext.Context, typattr.Type, val *big.Int, pathpath.Path) (attr.Value,diag.Diagnostics)
FromBigInt creates an attr.Value using `typ` from a *big.Int.
It is meant to be called through FromValue, not directly.
funcFromBool¶
func FromBool(ctxcontext.Context, typattr.Type, valbool, pathpath.Path) (attr.Value,diag.Diagnostics)
FromBool returns an attr.Value as produced by `typ` from a bool.
It is meant to be called through FromValue, not directly.
funcFromFloat¶
func FromFloat(ctxcontext.Context, typattr.Type, valfloat64, pathpath.Path) (attr.Value,diag.Diagnostics)
FromFloat creates an attr.Value using `typ` from a float64.
It is meant to be called through FromValue, not directly.
funcFromInt¶
func FromInt(ctxcontext.Context, typattr.Type, valint64, pathpath.Path) (attr.Value,diag.Diagnostics)
FromInt creates an attr.Value using `typ` from an int64.
It is meant to be called through FromValue, not directly.
funcFromMap¶
func FromMap(ctxcontext.Context, typattr.TypeWithElementType, valreflect.Value, pathpath.Path) (attr.Value,diag.Diagnostics)
FromMap returns an attr.Value representing the data contained in `val`.`val` must be a map type with keys that are a string type. The attr.Valuewill be of the type produced by `typ`.
It is meant to be called through FromValue, not directly.
funcFromNullable¶
func FromNullable(ctxcontext.Context, typattr.Type, valNullable, pathpath.Path) (attr.Value,diag.Diagnostics)
FromNullable creates an attr.Value from the data in a Nullable.
It is meant to be called through FromValue, not directly.
funcFromPointer¶
func FromPointer(ctxcontext.Context, typattr.Type, valuereflect.Value, pathpath.Path) (attr.Value,diag.Diagnostics)
FromPointer turns a pointer into an attr.Value using `typ`. If the pointeris nil, the attr.Value will use its null representation. If it is not nil,it will recurse into FromValue to find the attr.Value of the type the valuethe pointer is referencing.
It is meant to be called through FromValue, not directly.
funcFromSlice¶
func FromSlice(ctxcontext.Context, typattr.Type, valreflect.Value, pathpath.Path) (attr.Value,diag.Diagnostics)
FromSlice returns an attr.Value as produced by `typ` using the data in`val`. `val` must be a slice. `typ` must be an attr.TypeWithElementType orattr.TypeWithElementTypes. If the slice is nil, the representation of nullfor `typ` will be returned. Otherwise, FromSlice will recurse into FromValuefor each element in the slice, using the element type or types defined on`typ` to construct values for them.
It is meant to be called through FromValue, not directly.
funcFromString¶
func FromString(ctxcontext.Context, typattr.Type, valstring, pathpath.Path) (attr.Value,diag.Diagnostics)
FromString returns an attr.Value as produced by `typ` from a string.
It is meant to be called through FromValue, not directly.
funcFromStruct¶
func FromStruct(ctxcontext.Context, typattr.TypeWithAttributeTypes, valreflect.Value, pathpath.Path) (attr.Value,diag.Diagnostics)
FromStruct builds an attr.Value as produced by `typ` from the data in `val`.`val` must be a struct type, and must have all its properties tagged and bea 1:1 match with the attributes reported by `typ`. FromStruct will recurseinto FromValue for each attribute, using the type of the attribute asreported by `typ`.
It is meant to be called through FromValue, not directly.
funcFromUint¶
func FromUint(ctxcontext.Context, typattr.Type, valuint64, pathpath.Path) (attr.Value,diag.Diagnostics)
FromUint creates an attr.Value using `typ` from a uint64.
It is meant to be called through FromValue, not directly.
funcFromUnknownable¶
func FromUnknownable(ctxcontext.Context, typattr.Type, valUnknownable, pathpath.Path) (attr.Value,diag.Diagnostics)
FromUnknownable creates an attr.Value from the data in an Unknownable.
It is meant to be called through FromValue, not directly.
funcFromValue¶
func FromValue(ctxcontext.Context, typattr.Type, val interface{}, pathpath.Path) (attr.Value,diag.Diagnostics)
FromValue is the inverse of Into, taking a Go value (`val`) and transforming itinto an attr.Value using the attr.Type supplied. `val` will first betransformed into a tftypes.Value, then passed to `typ`'s ValueFromTerraformmethod.
funcFromValueCreator¶
func FromValueCreator(ctxcontext.Context, typattr.Type, valtftypes.ValueCreator, pathpath.Path) (attr.Value,diag.Diagnostics)
FromValueCreator creates an attr.Value from the data in atftypes.ValueCreator, calling its ToTerraform5Value method and convertingthe result to an attr.Value using `typ`.
It is meant to be called from FromValue, not directly.
funcInto¶
func Into(ctxcontext.Context, typattr.Type, valtftypes.Value, target interface{}, optsOptions, pathpath.Path)diag.Diagnostics
Into uses the data in `val` to populate `target`, using the reflectionpackage to recursively reflect into structs and slices. If `target` is anattr.Value, its assignment method will be used instead of reflecting. If`target` is a tftypes.ValueConverter, the FromTerraformValue method will beused instead of using reflection. Primitives are set using the val.Asmethod. Structs use reflection: each exported struct field must have a"tfsdk" tag with the name of the field in the tftypes.Value, and all fieldsin the tftypes.Value must have a corresponding property in the struct. Intowill be called for each struct field. Slices will have Into called for eachelement.
funcIsGenericAttrValue¶added inv0.6.0
funcMap¶
func Map(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
Map creates a map value that matches the type of `target`, and populates itwith the contents of `val`.
funcNewAttributeValue¶
func NewAttributeValue(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
NewAttributeValue creates a new reflect.Value by calling theValueFromTerraform method on `typ`. It will return an error if the returned`attr.Value` is not the same type as `target`.
It is meant to be called through Into, not directly.
funcNewNullable¶
func NewNullable(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
NewNullable creates a zero value of `target` (or the concrete type it'sreferencing, if it's a pointer) and calls its SetNull method.
It is meant to be called through Into, not directly.
funcNewUnknownable¶
func NewUnknownable(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
NewUnknownable creates a zero value of `target` (or the concrete type it'sreferencing, if it's a pointer) and calls its SetUnknown method.
It is meant to be called through Into, not directly.
funcNewValueConverter¶
func NewValueConverter(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
NewValueConverter creates a zero value of `target` (or the concrete typeit's referencing, if it's a pointer) and calls its FromTerraform5Valuemethod.
It is meant to be called through Into, not directly.
funcNumber¶
func Number(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
Number creates a *big.Float and populates it with the data in `val`. It thengets converted to the type of `target`, as long as `target` is a validnumber type (any of the built-in int, uint, or float types, *big.Float, and*big.Int).
Number will loudly fail when a number cannot be losslessly represented usingthe requested type.
It is meant to be called through Into, not directly.
funcPointer¶
func Pointer(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
Pointer builds a new zero value of the concrete type that `target`references, populates it with BuildValue, and takes a pointer to it.
It is meant to be called through Into, not directly.
funcPrimitive¶
func Primitive(ctxcontext.Context, typattr.Type, valtftypes.Value, targetreflect.Value, pathpath.Path) (reflect.Value,diag.Diagnostics)
Primitive builds a string or boolean, depending on the type of `target`, andpopulates it with the data in `val`.
It is meant to be called through `Into`, not directly.
funcStruct¶
func Struct(ctxcontext.Context, typattr.Type, objecttftypes.Value, targetreflect.Value, optsOptions, pathpath.Path) (reflect.Value,diag.Diagnostics)
Struct builds a new struct using the data in `object`, as long as `object`is a `tftypes.Object`. It will take the struct type from `target`, whichmust be a struct type.
The properties on `target` must be tagged with a "tfsdk" label containingthe field name to map to that property. Every property must be tagged, andevery property must be present in the type of `object`, and all theattributes in the type of `object` must have a corresponding property.Properties that don't map to object attributes must have a `tfsdk:"-"` tag,explicitly defining them as not part of the object. This is to catch typosand other mistakes early.
Struct is meant to be called from Into, not directly.
Types¶
typeDiagIntoIncompatibleType¶added inv0.3.0
func (DiagIntoIncompatibleType)Detail¶added inv0.3.0
func (dDiagIntoIncompatibleType) Detail()string
func (DiagIntoIncompatibleType)Equal¶added inv0.3.0
func (dDiagIntoIncompatibleType) Equal(odiag.Diagnostic)bool
func (DiagIntoIncompatibleType)Severity¶added inv0.3.0
func (dDiagIntoIncompatibleType) Severity()diag.Severity
func (DiagIntoIncompatibleType)Summary¶added inv0.3.0
func (dDiagIntoIncompatibleType) Summary()string
typeDiagNewAttributeValueIntoWrongType¶added inv0.3.0
type DiagNewAttributeValueIntoWrongType struct {ValTypereflect.TypeTargetTypereflect.TypeSchemaTypeattr.Type}func (DiagNewAttributeValueIntoWrongType)Detail¶added inv0.3.0
func (dDiagNewAttributeValueIntoWrongType) Detail()string
func (DiagNewAttributeValueIntoWrongType)Equal¶added inv0.3.0
func (dDiagNewAttributeValueIntoWrongType) Equal(odiag.Diagnostic)bool
func (DiagNewAttributeValueIntoWrongType)Severity¶added inv0.3.0
func (dDiagNewAttributeValueIntoWrongType) Severity()diag.Severity
func (DiagNewAttributeValueIntoWrongType)Summary¶added inv0.3.0
func (dDiagNewAttributeValueIntoWrongType) Summary()string
typeNullable¶
type Nullable interface {SetNull(context.Context,bool)errorSetValue(context.Context, interface{})errorGetNull(context.Context)boolGetValue(context.Context) interface{}}Nullable is an interface for types that can be explicitly set to null.
typeOptions¶
type Options struct {// UnhandledNullAsEmpty controls whether null values should be// translated into empty values without provider interaction, or if// they must be explicitly handled.UnhandledNullAsEmptybool// UnhandledUnknownAsEmpty controls whether null values should be// translated into empty values without provider interaction, or if// they must be explicitly handled.UnhandledUnknownAsEmptybool}Options provides configuration settings for how the reflection behaviorworks, letting callers tweak different behaviors based on their needs.