cfgmetadata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(loaders ...Loader) error

func PathKeyMaker

func PathKeyMaker(s []string, tag *reflect.StructTag) (string, error)

PathKeyMaker joins names of struct fields with dot character.

func PrintFieldsWithTemplate

func PrintFieldsWithTemplate(m *MetaData, w io.Writer, t string, fmap map[string]interface{}) (err error)

func TagKeyMaker

func TagKeyMaker(tagName string, autoNaming bool) func([]string, *reflect.StructTag) (string, error)

Types

type Converter

type Converter interface {
	Applies(value reflect.Value) bool
	StoreString(value reflect.Value, s string) error
	ToString(value reflect.Value) (string, error)
}

type Converters

type Converters []Converter

func (Converters) Append

func (c Converters) Append(cs ...Converter) Converters

func (Converters) ConvertToString

func (c Converters) ConvertToString(value reflect.Value) (bool, string, error)

func (Converters) LoadFromString

func (c Converters) LoadFromString(value reflect.Value, s string) (bool, error)

type DurationConverter

type DurationConverter struct{}

func (DurationConverter) Applies

func (_ DurationConverter) Applies(value reflect.Value) bool

func (DurationConverter) StoreString

func (_ DurationConverter) StoreString(value reflect.Value, s string) error

func (DurationConverter) ToString

func (_ DurationConverter) ToString(value reflect.Value) (string, error)

type Loader

type Loader interface {
	Load() error
}

type MetaData

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

func NewMetadata

func NewMetadata(i interface{}, o Options) (m *MetaData, err error)

func (*MetaData) AddConverters

func (m *MetaData) AddConverters(converters ...Converter) *MetaData

func (*MetaData) GetField

func (m *MetaData) GetField(key string) *MetaDataField

func (*MetaData) GetFields

func (m *MetaData) GetFields() []MetaDataField

func (*MetaData) GetKeys

func (m *MetaData) GetKeys() []string

func (*MetaData) GetObject

func (m *MetaData) GetObject() interface{}

func (*MetaData) SetFieldValue

func (m *MetaData) SetFieldValue(key string, value string) error

type MetaDataField

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

func (*MetaDataField) FullKey

func (f *MetaDataField) FullKey() string

func (*MetaDataField) IsNil

func (f *MetaDataField) IsNil() bool

func (*MetaDataField) Key

func (f *MetaDataField) Key() string

func (*MetaDataField) StringValue

func (f *MetaDataField) StringValue() string

func (*MetaDataField) Tag

func (f *MetaDataField) Tag(key string) string

func (*MetaDataField) Type

func (f *MetaDataField) Type() reflect.Type

func (*MetaDataField) Value

func (f *MetaDataField) Value() interface{}

type Options

type Options struct {
	// Generates key which will be used for fields lookup
	KeyMakerFunc func([]string, *reflect.StructTag) (string, error)

	// If set to true, sub structures can be defined using string representation.
	// The format of string is defined by ComplexFieldsUnmarshaler
	AllowParsingSubStructures bool

	// Function which will unmarshal sub structures, slice or maps.
	ComplexFieldsUnmarshaler func([]byte, interface{}) error

	// Function which will marshal sub structures, slices or maps.
	// Usually is used for string representations.
	ComplexFieldsMarshaler func(interface{}) ([]byte, error)

	Loggerf func(string, ...interface{})

	// If true, maps will be owerwritten by making new map,
	// In opposite case they will be updated
	OverwriteMaps bool
}

type TextMarshallerConverter

type TextMarshallerConverter struct{}

func (TextMarshallerConverter) Applies

func (TextMarshallerConverter) Applies(value reflect.Value) bool

func (TextMarshallerConverter) StoreString

func (TextMarshallerConverter) StoreString(value reflect.Value, s string) error

func (TextMarshallerConverter) ToString

func (TextMarshallerConverter) ToString(value reflect.Value) (string, error)

Jump to

Keyboard shortcuts

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