config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Realpath = func(ctx context.Context, value interface{}) (interface{}, error) {
	ctxPathPrefix := ctx.Value("PATH_PREFIX")
	if ctxPathPrefix != nil {
		if prefixPath, ok := ctxPathPrefix.(string); ok {
			if path, ok := value.(string); ok {
				if path != "" {
					if !strings.HasPrefix(path, "/") {
						return strings.TrimRight(prefixPath, "/") + "/" + path, nil
					}
				}
			}
		}
	}
	return value, nil
}

Functions

func Register

func Register(name string, configHandler configHandler) error

func Use

func Use(name string) (configHandler, error)

Types

type Callback

type Callback func(ctx context.Context, value interface{}) (interface{}, error)

type Handler

type Handler interface {
	Initiate(ctx context.Context) error
	AddConfigPath(in string)
	SetConfigName(in string)
	SetConfigFile(in string)
	ConfigFileUsed() string
	SetDefault(key string, value interface{})
	BindEnv(in string) error
	SetEnvPrefix(in string)
	ReadInConfig() error
	Set(key string, value interface{})
	Get(key string) interface{}
	// GetString returns the value associated with the key as a string.
	GetString(key string) string
	// GetBool returns the value associated with the key as a boolean.
	GetBool(key string) bool
	// GetInt returns the value associated with the key as an integer.
	GetInt(key string) int
	// GetInt64 returns the value associated with the key as an integer.
	GetInt64(key string) int64
	// GetFloat64 returns the value associated with the key as a float64.
	GetFloat64(key string) float64
	// GetTime returns the value associated with the key as time.
	GetTime(key string) time.Time
	// GetDuration returns the value associated with the key as a duration.
	GetDuration(key string) time.Duration
	// GetStringSlice returns the value associated with the key as a slice of strings.
	GetStringSlice(key string) []string
	// GetStringMap returns the value associated with the key as a map of interfaces.
	GetStringMap(key string) map[string]interface{}
	// GetStringMapString returns the value associated with the key as a map of strings.
	GetStringMapString(key string) map[string]string
	// GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
	GetStringMapStringSlice(key string) map[string][]string
	// GetSizeInBytes returns the size of the value associated with the given key
	// in bytes.
	GetSizeInBytes(key string) uint
}

func NewViperHandler

func NewViperHandler() Handler

type Instance

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

func NewInstance

func NewInstance() *Instance

func (*Instance) AddConfigPath

func (this *Instance) AddConfigPath(in string)

func (*Instance) BindedEnvironmentKeys

func (this *Instance) BindedEnvironmentKeys() []string

func (*Instance) Callbacks

func (this *Instance) Callbacks(ctx context.Context, callbacks map[string]Callback) (context.Context, error)

func (*Instance) ConfigFileUsed

func (this *Instance) ConfigFileUsed() string

func (*Instance) GetBool

func (this *Instance) GetBool(key string) bool

GetBool returns the value associated with the key as a boolean.

func (*Instance) GetDuration

func (this *Instance) GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration.

func (*Instance) GetFloat64

func (this *Instance) GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64.

func (*Instance) GetInt

func (this *Instance) GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func (*Instance) GetInt64

func (this *Instance) GetInt64(key string) int64

GetInt64 returns the value associated with the key as an integer.

func (*Instance) GetPathPrefix

func (this *Instance) GetPathPrefix() string

func (*Instance) GetSizeInBytes

func (this *Instance) GetSizeInBytes(key string) uint

GetSizeInBytes returns the size of the value associated with the given key in bytes.

func (*Instance) GetString

func (this *Instance) GetString(key string) string

GetString returns the value associated with the key as a string.

func (*Instance) GetStringMap

func (this *Instance) GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as a map of interfaces.

func (*Instance) GetStringMapString

func (this *Instance) GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func (*Instance) GetStringMapStringSlice

func (this *Instance) GetStringMapStringSlice(key string) map[string][]string

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.

func (*Instance) GetStringSlice

func (this *Instance) GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func (*Instance) GetTime

func (this *Instance) GetTime(key string) time.Time

GetTime returns the value associated with the key as time.

func (*Instance) GetValue

func (this *Instance) GetValue(key string) interface{}

func (*Instance) HandlerName

func (this *Instance) HandlerName() string

func (*Instance) Initiate

func (this *Instance) Initiate(ctx context.Context) (context.Context, error)

func (*Instance) LoadFromConfigFile

func (this *Instance) LoadFromConfigFile(configFile string) error

func (*Instance) LoadFromConfigPath

func (this *Instance) LoadFromConfigPath(configName string) error

func (*Instance) LoadFromEnv

func (this *Instance) LoadFromEnv() error

func (*Instance) LoadFromEnvFile

func (this *Instance) LoadFromEnvFile(dotEnvFile string) error

func (*Instance) OnRequestShutdown

func (this *Instance) OnRequestShutdown(c *routing.Context) error

func (*Instance) OnRequestStartup

func (this *Instance) OnRequestStartup(c *routing.Context) error

func (*Instance) OnShutdown

func (this *Instance) OnShutdown(ctx context.Context) (context.Context, error)

func (*Instance) OnStartup

func (this *Instance) OnStartup(ctx context.Context) (context.Context, error)

func (*Instance) SetEnvPrefix

func (this *Instance) SetEnvPrefix(in string)

func (*Instance) SetOptions

func (this *Instance) SetOptions(ctx context.Context, options map[string]Option) (context.Context, error)

func (*Instance) SetPathPrefix

func (this *Instance) SetPathPrefix(pathPrefix string)

func (*Instance) SetValue

func (this *Instance) SetValue(key string, value interface{})

func (*Instance) Use

func (this *Instance) Use(ctx context.Context, handlerName string) error

func (*Instance) WithContextValue

func (this *Instance) WithContextValue(ctx context.Context, keymaps map[string]string)

type Option

type Option struct {
	Type           Type
	Default        interface{}
	EnvironmentKey string
}

type Type

type Type uint
const (
	Invalid Type = iota
	String
	Bool
	Int
	Int64
	Float64
	Time
	Duration
	StringSlice
	StringMap
	StringMapString
	StringMapStringSlice
	SizeInBytes
)

type ViperHandler

type ViperHandler struct {
	Viper *viper.Viper
}

func (*ViperHandler) AddConfigPath

func (this *ViperHandler) AddConfigPath(in string)

func (*ViperHandler) BindEnv

func (this *ViperHandler) BindEnv(in string) error

func (*ViperHandler) ConfigFileUsed

func (this *ViperHandler) ConfigFileUsed() string

func (*ViperHandler) Get

func (this *ViperHandler) Get(key string) interface{}

func (*ViperHandler) GetBool

func (this *ViperHandler) GetBool(key string) bool

GetBool returns the value associated with the key as a boolean.

func (*ViperHandler) GetDuration

func (this *ViperHandler) GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration.

func (*ViperHandler) GetFloat64

func (this *ViperHandler) GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64.

func (*ViperHandler) GetInt

func (this *ViperHandler) GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func (*ViperHandler) GetInt64

func (this *ViperHandler) GetInt64(key string) int64

GetInt64 returns the value associated with the key as an integer.

func (*ViperHandler) GetSizeInBytes

func (this *ViperHandler) GetSizeInBytes(key string) uint

GetSizeInBytes returns the size of the value associated with the given key in bytes.

func (*ViperHandler) GetString

func (this *ViperHandler) GetString(key string) string

GetString returns the value associated with the key as a string.

func (*ViperHandler) GetStringMap

func (this *ViperHandler) GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as a map of interfaces.

func (*ViperHandler) GetStringMapString

func (this *ViperHandler) GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func (*ViperHandler) GetStringMapStringSlice

func (this *ViperHandler) GetStringMapStringSlice(key string) map[string][]string

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.

func (*ViperHandler) GetStringSlice

func (this *ViperHandler) GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func (*ViperHandler) GetTime

func (this *ViperHandler) GetTime(key string) time.Time

GetTime returns the value associated with the key as time.

func (*ViperHandler) Initiate

func (this *ViperHandler) Initiate(ctx context.Context) error

func (*ViperHandler) ReadInConfig

func (this *ViperHandler) ReadInConfig() error

func (*ViperHandler) Set

func (this *ViperHandler) Set(key string, value interface{})

func (*ViperHandler) SetConfigFile

func (this *ViperHandler) SetConfigFile(in string)

func (*ViperHandler) SetConfigName

func (this *ViperHandler) SetConfigName(in string)

func (*ViperHandler) SetDefault

func (this *ViperHandler) SetDefault(key string, value interface{})

func (*ViperHandler) SetEnvPrefix

func (this *ViperHandler) SetEnvPrefix(in string)

Jump to

Keyboard shortcuts

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