hooks

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2018 License: Apache-2.0 Imports: 5 Imported by: 2

README

GoDoc Go Report Card Build Status

About

This is a small extension to Mitshell Hashimoto's excellent library mapstructure. It allows one to fill arrays of interfaces whose concrete type is determined by their content. A typical usecase is configuring log handlers from a yaml file and processing the imported map through mapstructure.

The design was heavily inspired by logrus_mate

Usage

For a detailled description look at the examples in the godocs.

Documentation

Overview

Package hooks helps to configure hook configurations from a map. It's a wrapper around mapstructure.

The main functions to be used are:

RegisterInterface: just use once to register an interface type
Register:          used to register possible kinds of an interface
Decode:            used once to decode the config

All other functions are for advanced uses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(in, out interface{}) error

Decode transkripts map[interface{}]interface{} to the target struct

func DecodeElementsHookFunc

func DecodeElementsHookFunc() mapstructure.DecodeHookFunc

DecodeElementsHookFunc returns a DecodeHookFunc that converts maps to a Hook config derived from a registry.

func DefaultDecoderConfig

func DefaultDecoderConfig(output interface{}) *mapstructure.DecoderConfig

DefaultDecoderConfig returns default mapstructure.DecoderConfig with support of time.Duration values and Plugins

func InitRegistry

func InitRegistry()

InitRegistry resets the registry. It is intended mainly for testing.

func Register

func Register(forType reflect.Type, kind string, f func() interface{})

Register registers the factory function for all instances of a given type hint: provide a type for consumers with MyHookType := reflect.TypeOf((*MyHook)(nil)).Elem()

func RegisterInterface

func RegisterInterface(forType reflect.Type, key string)

RegisterInterface registers a new interface type; must only be called once!

func StringToStringUnmarshallerHookFunc

func StringToStringUnmarshallerHookFunc() mapstructure.DecodeHookFunc

StringToStringUnmarshallerHookFunc returns a DecodeHookFunc that converts strings by an unmarshaller. Can be used to construct custom DecodeHookFunctions.

Types

type NewHookFunc

type NewHookFunc func() interface{}

NewHookFunc creates a new instance for an registered interface.

Jump to

Keyboard shortcuts

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