i2s

package
v0.0.0-...-93b1e75 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package i2s provides convertor from raw data representation as map[string]interface{} into external structure using reflection. It can also convert []map[string]interface{} or []interface{} into slice of structures.

Designed to be used inside config package with data unmarshalled by json, yaml, toml or any other such encoders.

It provides singleton Convertor instance that must be obtained with Instance function.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMismatchedTypes error is returned when types of input and output fields doesn't match.
	ErrMismatchedTypes = errors.New("mismatched types")

	// ErrMapKeyNotString error is returned when some map has keys with type different from string.
	ErrMapKeyNotString = errors.New("map keys must be strings")

	// ErrOutputNotPointer error is returned when provided output parameter is not a pointer.
	ErrOutputNotPointer = errors.New("output must be a pointer")

	// ErrUnknownField error is returned when output structure doesn't have an appropriate field for input data.
	ErrUnknownField = errors.New("unknown field")

	// ErrUnsupportedType error is returned when source contains data of type unsupported by this package.
	ErrUnsupportedType = errors.New("unsupported type")
)

Functions

This section is empty.

Types

type Convertor

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

Convertor structure that provides converting functionality. Don't create it manually, use Instance function instead.

func Instance

func Instance() *Convertor

Instance function retrieves Convertor singleton instance.

func (*Convertor) Convert

func (c *Convertor) Convert(data interface{}, out interface{}) error

Convert method converts raw data in 'data' parameter into structure (or slice of structures) that 'out' parameter points to. It will return an error if the structure doesn't have some field or it is not of an appropriate type.

Jump to

Keyboard shortcuts

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