typefactory

package
v0.1.46-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

typefactory/typefactory.go

internal/typefactory/hooks.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringToBoolHook

func StringToBoolHook(
	from reflect.Kind,
	to reflect.Kind,
	data interface{},
) (interface{}, error)

StringToBoolHook converts string values to booleans during decoding.

func StringToFloatHook

func StringToFloatHook(
	from reflect.Kind,
	to reflect.Kind,
	data interface{},
) (interface{}, error)

StringToFloatHook converts string values to floats during decoding.

func StringToIntHook

func StringToIntHook(
	from reflect.Kind,
	to reflect.Kind,
	data interface{},
) (interface{}, error)

StringToIntHook converts string values to integers during decoding.

func StringToIntHookFunc

func StringToIntHookFunc() mapstructure.DecodeHookFunc

StringToIntHookFunc converts a string to an int, defaulting to 0 if parsing fails

func StringToMapStringHookFunc

func StringToMapStringHookFunc() mapstructure.DecodeHookFunc

stringToMapStringHookFunc converts a string to a map[string]string by returning an empty map

func StringToSliceHook

func StringToSliceHook(
	from reflect.Kind,
	to reflect.Kind,
	data interface{},
) (interface{}, error)

StringToSliceHook converts comma-separated strings to slices of strings.

func StringToSliceHookFunc

func StringToSliceHookFunc() mapstructure.DecodeHookFunc

stringToSliceHookFunc converts a single string to a []string

Types

type TypeFactory

type TypeFactory struct {
	// contains filtered or unexported fields
}

TypeFactory is responsible for creating instances of types based on type names.

func NewTypeFactory

func NewTypeFactory() *TypeFactory

NewTypeFactory initializes a new TypeFactory.

func (*TypeFactory) CreateInstance

func (tf *TypeFactory) CreateInstance(request TypeRequest) (*TypeResponse, error)

CreateInstance creates an instance of the requested type and validates it.

func (*TypeFactory) RegisterType

func (tf *TypeFactory) RegisterType(typeName string, typ reflect.Type)

RegisterType registers a new type with the factory.

type TypeRequest

type TypeRequest struct {
	TypeName string
	Data     map[string]interface{}
}

TypeRequest represents a request to create an instance of a type.

type TypeResponse

type TypeResponse struct {
	Instance interface{}
	Warnings []string
	Error    error
}

TypeResponse represents the response from TypeFactory.

Jump to

Keyboard shortcuts

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