Movatterモバイル変換


[0]ホーム

URL:


reflect

package
v1.17.0Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License:MPL-2.0Imports:14Imported by:0

Details

Repository

github.com/hashicorp/terraform-plugin-framework

Links

Documentation

Overview

Package reflect contains the implementation for converting framework-defineddata into and from provider-defined Go types.

Index

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

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

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.

funcIsGenericAttrValueadded inv0.6.0

func IsGenericAttrValue(ctxcontext.Context, target interface{})bool

funcMap

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

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

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

typeDiagIntoIncompatibleTypeadded inv0.3.0

type DiagIntoIncompatibleType struct {Valtftypes.ValueTargetTypereflect.TypeErrerror}

func (DiagIntoIncompatibleType)Detailadded inv0.3.0

func (DiagIntoIncompatibleType)Equaladded inv0.3.0

func (DiagIntoIncompatibleType)Severityadded inv0.3.0

func (DiagIntoIncompatibleType)Summaryadded inv0.3.0

typeDiagNewAttributeValueIntoWrongTypeadded inv0.3.0

type DiagNewAttributeValueIntoWrongType struct {ValTypereflect.TypeTargetTypereflect.TypeSchemaTypeattr.Type}

func (DiagNewAttributeValueIntoWrongType)Detailadded inv0.3.0

func (DiagNewAttributeValueIntoWrongType)Equaladded inv0.3.0

func (DiagNewAttributeValueIntoWrongType)Severityadded inv0.3.0

func (DiagNewAttributeValueIntoWrongType)Summaryadded inv0.3.0

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.

typeUnknownable

type Unknownable interface {SetUnknown(context.Context,bool)errorSetValue(context.Context, interface{})errorGetUnknown(context.Context)boolGetValue(context.Context) interface{}}

Unknownable is an interface for types that can be explicitly set to known orunknown.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp