mapper

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TagField      TagField  `yaml:"tagField"`
	IgnoredFields []string  `yaml:"ignoredFields"`
	Mappings      []Mapping `yaml:"mappings"`
}

type Mapper

type Mapper struct {

	//key is Go Type name, value is mapping configuration
	Mappings map[string]Mapping
	// contains filtered or unexported fields
}

Mapper defines rules on how to map a Go Type to a model.Resource

func New

func New(config []byte, logger zap.Logger, providerValue reflect.Value) (Mapper, error)

func (Mapper) FetchResources

func (m Mapper) FetchResources(ctx context.Context, region string) ([]*model.Resource, error)

FetchResources calls the implementation method on each Mapping and returns the resources

func (Mapper) ToResource

func (m Mapper) ToResource(ctx context.Context, x any, region string) (model.Resource, error)

ToResource generate a Resource by using reflection all fields will become properties if there is a Tags field, this will become Tags

type Mapping

type Mapping struct {
	Type string `yaml:"type"`
	//optional: if the Resource Type is different that the Golang type
	ResourceType string `yaml:"resourceType"`
	//optional: if the ID field is not called 'Id'
	IdField string `default:"Id" yaml:"idField"`
	//optional: override the TagField from MappingConfig
	TagField TagField `yaml:"tagField"`
	//optional: override the IgnoredFields from MappingConfig
	IgnoredFields []string `yaml:"ignoredFields"`
	//method implementating fetching the resources, the provider must implement it
	Impl string `yaml:"impl"`
	//the method is found at runtime using Impl
	Method *reflect.Value
	//optional: method implementating fetching the tags, only needed if there is not a field containing tags
	TagImpl string `yaml:"tagImpl"`
	//the method is found at runtime using TagImpl
	TagMethod *reflect.Value
}

type TagField

type TagField struct {
	//how to fetch the tags
	//field name
	Name string `yaml:"name"`
	//name of key attribute
	Key string `yaml:"key"`
	//name of value attribute
	Value string `yaml:"value"`
}

Jump to

Keyboard shortcuts

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