Documentation ¶
Overview ¶
Package kvstructure implements to transcode and transdecode data structures into Key-Value Stores.
See https://github.com/docker/libkv for all supported KV.
Index ¶
- Constants
- func Transcode(name string, s interface{}, prefix string, kv store.Store) error
- func TranscoderWithKV(kv store.Store) func(o *TranscoderOpts)
- func TranscoderWithPrefix(prefix string) func(o *TranscoderOpts)
- func Transdecode(name string, s interface{}, prefix string, kv store.Store) error
- func TransdecoderWithKV(kv store.Store) func(o *TransdecoderOpts)
- func TransdecoderWithPrefix(prefix string) func(o *TransdecoderOpts)
- type Metadata
- type Transcoder
- type TranscoderOpt
- type TranscoderOpts
- type Transdecoder
- type TransdecoderOpt
- type TransdecoderOpts
Constants ¶
const Version = "0.1.1"
Variables ¶
This section is empty.
Functions ¶
func TranscoderWithKV ¶
func TranscoderWithKV(kv store.Store) func(o *TranscoderOpts)
TranscoderWithKV ...
func TranscoderWithPrefix ¶
func TranscoderWithPrefix(prefix string) func(o *TranscoderOpts)
TranscoderWithPrefix ...
func Transdecode ¶
Transdecode takes an interface and uses reflection to fill it with data from a kv.
func TransdecoderWithKV ¶
func TransdecoderWithKV(kv store.Store) func(o *TransdecoderOpts)
TransdecoderWithKV ...
func TransdecoderWithPrefix ¶
func TransdecoderWithPrefix(prefix string) func(o *TransdecoderOpts)
TransdecoderWithPrefix ...
Types ¶
type Metadata ¶
type Metadata struct { // Keys are the keys of the structure which were successfully decoded Keys []string // Unused is a slice of keys that were found in the raw value but // weren't decoded since there was no matching field in the result interface Unused []string }
Metadata contains information about decoding a structure that is tedious or difficult to get otherwise.
type Transcoder ¶
Transcoder is the interface to a transcoder
func NewTranscoder ¶
func NewTranscoder(opts ...TranscoderOpt) (Transcoder, error)
NewTranscoder returns a new transcoder for the given configuration. Once a transcoder has been returned, the same interface must be used.
transcoder, err := NewTranscoder( TranscoderWithKV(kv), TranscoderWithPrefix("prefix"), ) if err != nil { return err } tt := &Example{ Description: "bar", Enabled: true, } if err := transcoder.Transcode("foo", &tt) { return err }
type TranscoderOpts ¶
type TranscoderOpts struct { // Metadata is the struct that will contain extra metadata about // the decoding. If this is nil, then no metadata will be tracked. Metadata *Metadata // The tag name that kvstructure reads for field names. This // defaults to "kvstructure" TagName string // Prefix is the prefix of the store Prefix string // KV is the kv used to retrieve the needed infos KV store.Store }
TranscoderOpts is the configuration that is used to create a new transcoder and allows customization of various aspects of decoding.
type Transdecoder ¶
Transdecoder is the interface to a transdecoder
func NewTransdecoder ¶
func NewTransdecoder(opts ...TransdecoderOpt) (Transdecoder, error)
NewTransdecoder returns a new transdecoder for the given configuration. Once a transdecoder has been returned, the same configuration must not be used again.
type TransdecoderOpts ¶
type TransdecoderOpts struct { // ZeroFields, if set to true, will zero fields before writing them. // For example, a map will be emptied before decoded values are put in // it. If this is false, a map will be merged. ZeroFields bool // should be done later WeaklyTypedInput bool // Metadata is the struct that will contain extra metadata about // the decoding. If this is nil, then no metadata will be tracked. Metadata *Metadata // The tag name that kvstructure reads for field names. This // defaults to "kvstructure" TagName string // Prefix is the prefix of the store Prefix string // KV is the kv used to retrieve the needed infos KV store.Store }
TransdecoderOpts is the configuration that is used to create a new transdecoder and allows customization of various aspects of decoding.