Help us shape the future of Go! Take the 2026 Go Developer Survey

tagconfig

package module
v0.0.0-...-21c5ab6 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2016 License: MIT Imports: 6 Imported by: 4

README

TagConfig

An adaptation of Kelsey Hightower's envconfig, allowing for custom KV stores rather than just environment variables.

Documentation

Overview

MIT Licensed

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSpecification = errors.New("specification must be a struct pointer")

ErrInvalidSpecification indicates that a specification is of the wrong type.

Functions

func MustProcess

func MustProcess(v TagValueGetter, spec interface{})

MustProcess is the same as Process but panics if an error occurs

func PopulateExternalSource

func PopulateExternalSource(v TagValueSetter, spec interface{}) error

PopulateExternalSource is used to fill an external source when a struct contains values. An external source can include an in memory store, environment variables, a properties store, and so forth. Therefore, if a struct contains values, but you want to propagate said values to another location, this would allow you to do so based off of how the TagValueSetter has been implemented.

func Process

func Process(v TagValueGetter, spec interface{}) error

Process populates the specified struct based on the TagValueGetter implementation

Types

type Decoder

type Decoder interface {
	Decode(value string) error
}

A Decoder is a type that knows how to de-serialize environment variables into itself.

type ParseError

type ParseError struct {
	FieldName string
	TypeName  string
	Value     string
}

A ParseError occurs when an environment variable cannot be converted to the type required by a struct field during assignment.

func (*ParseError) Error

func (e *ParseError) Error() string

type TagNameGetter

type TagNameGetter interface {
	TagName() string
}

TagNameGetter is used for defining a struct tag that contains the value in question.

type TagValueGetter

type TagValueGetter interface {
	TagNameGetter
	Get(key string, t reflect.StructField) string
}

TagValueGetter is an interface to allow for different k,v stores to be passed to the Process func. TagName is the name of the tag Process looks for, to query the TagValueGetter Get is passed a key to look up and the StructField so it can inspect for other tags it might care about.

type TagValueSetter

type TagValueSetter interface {
	TagNameGetter
	Set(key string, value interface{}, t reflect.StructField) error
}

TagValueSetter is used to set a value onto an external source based on the tag name.

Jump to

Keyboard shortcuts

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