handler

package
v0.0.0-...-ed5747a Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2018 License: MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Default Use the default handler
	Default = "Default"

	// Override Use the Override handler
	Override = "Override"

	// Environment Use the environment handler
	Environment = "Environment"

	// Ini Use the ini handler
	Ini = "Ini"
)

Variables

This section is empty.

Functions

func Apply

func Apply(keyFunc KeyFunc, valueFunc ValueFunc, handler cfg.Handler) cfg.Handler

Apply creates a new Apply Handler. An Apply handler applies the given key and value funcs to the key/value before calling the underlying handler. The funcs are only called if they aren't nil.

An Apply handler can be used to transform values. For example, if keys should always be in lower case you can apply a key func to lower case the keys.

func ApplyKey

func ApplyKey(keyFunc KeyFunc, handler cfg.Handler) cfg.Handler

ApplyKey creates a new Apply handler with the specified KeyFunc.

func ApplyValue

func ApplyValue(valueFunc ValueFunc, handler cfg.Handler) cfg.Handler

ApplyValue creates a new Apply handler with the specified ValueFunc.

func ByName

func ByName(handlers ...*HandlerName) cfg.Handler

ByName creates a new handler that maps a list of handlers to their name. You can then do get and set operations against a named handler.

func Env

func Env() cfg.Handler

Env returns a Handler that access keys that are environment variables.

func EnvUpper

func EnvUpper() cfg.Handler

EnvUpper returns a Env handler that first upper cases all keys before getting or setting them.

func Loader

func Loader(loader cfg.Loader) cfg.Handler

Loader returns a handler that reads the keys in from a loader.

func LowercaseKey

func LowercaseKey(handler cfg.Handler) cfg.Handler

LowercaseKey creates a new Apply handler that lower cases all keys.

func Map

func Map() cfg.Handler

Map creates a handler that stores all values in a hashmap. It is commonly used as a component to build more complex handlers.

func MapUse

func MapUse(values map[string]interface{}) cfg.Handler

MapUse creates a Map handler that is preloaded with the hashmap passed in.

func Multi

func Multi(handlers ...cfg.Handler) cfg.Handler

Multi takes a list of Handlers and returns a single Handler that calls them. The handlers are called in the order they are specified.

func PrefixKey

func PrefixKey(handler cfg.Handler, prefix string) cfg.Handler

PrefixKey will prefix all keys with the given prefix string.

func Prioritized

func Prioritized(handlers ...*HandlerName) cfg.Handler

Prioritized creates a new Prioritized Handler. A Prioritized Handler performs look ups in the order they were given. In addition the name of a handler can be passed as the last argument to a set or get. If this is done, then the named handler is used.

func Sync

func Sync(handler cfg.Handler) *syncHandler

Sync creates a Handler that can be safely accessed by multiple threads. It ensures that the Init method only initializes a handler one time, regardless of the number of threads that call it.

func UppercaseKey

func UppercaseKey(handler cfg.Handler) cfg.Handler

UppercaseKey creates a new Apply handler that upper cases all keys.

func Viper

func Viper(loader cfg.Loader) cfg.Handler

Viper implements github.com/spf13/viper

func ViperCaseSensitive

func ViperCaseSensitive(loader cfg.Loader) cfg.Handler

ViperCaseSensitive implements github.com/spf13/viper except that keys are case sensitive.

func ViperEx

func ViperEx(loader cfg.Loader) cfg.Handler

ViperEx implements github.com/spf13/viper with the addition of environment variables checked before checking for values in the ini file(s).

func ViperExCaseSensitive

func ViperExCaseSensitive(loader cfg.Loader) cfg.Handler

ViperExCaseSensitive implements ViperEx except that keys are case sensitive.

Types

type HandlerName

type HandlerName struct {
	Name    string
	Handler cfg.Handler
}

A HandlerName associates a name with a given handler.

func NameHandler

func NameHandler(name string, handler cfg.Handler) *HandlerName

NameHandler is a convenience function for creating new instances of a HandlerName type.

type HandlerNames

type HandlerNames []*HandlerName

HandlerNames is list of HandlerName. The type allows us to add convenience functions to lists of HandlerName.

func (HandlerNames) ToHandlers

func (hns HandlerNames) ToHandlers() []cfg.Handler

ToHandlers returns the handlers in an array of HandlerName.

func (HandlerNames) ToMap

func (hns HandlerNames) ToMap() map[string]*HandlerName

ToMap returns a map from an array of HandlerName.

func (HandlerNames) ToNames

func (hns HandlerNames) ToNames() []string

ToNames returns the name in an arry of HandlerName.

type HotSwapHandler

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

HotSwapHandler holds a swappable handler. It is safe to swap this handler at run even if used by multiple threads.

func HotSwap

func HotSwap(handler cfg.Handler) *HotSwapHandler

HotSwap creates a hot swappable handler.

func (*HotSwapHandler) Args

func (h *HotSwapHandler) Args() bool

Args returns true if the underlying handler supports multiple args. It is thread safe.

func (*HotSwapHandler) Get

func (h *HotSwapHandler) Get(key string, args ...interface{}) (interface{}, error)

Get retrieves key values. It is thread safe.

func (*HotSwapHandler) Init

func (h *HotSwapHandler) Init() error

Init initializes the handler. It is thread safe.

func (*HotSwapHandler) Set

func (h *HotSwapHandler) Set(key string, value interface{}, args ...interface{}) error

Set sets a key to a value. It is thread safe.

func (*HotSwapHandler) SwapHandler

func (h *HotSwapHandler) SwapHandler(newHandler cfg.Handler)

SwapHandler allows a handler to be swapped in a thread safe fashion. You need to call init before using the handler.

func (*HotSwapHandler) SwapHandlerInit

func (h *HotSwapHandler) SwapHandlerInit(newHandler cfg.Handler) error

SwapHandlerInit allows a handler to be swapped in a thread safe fashion. It also calls Init and returns the result.

type KeyFunc

type KeyFunc func(key string) (string, error)

KeyFunc is the type of a function to apply to a key to produce a transformed one.

type ValueFunc

type ValueFunc func(value interface{}) (interface{}, error)

ValueFunc is the type of a function to apply to a value to produce a transformed one.

Jump to

Keyboard shortcuts

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