config

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 15 Imported by: 9

Documentation

Overview

Package config manages configurations of application.

Package config manages configurations of application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDataSource

func AddDataSource(data []byte, ct string)

AddDataSource add a config source with bytes and type.

func AddFileSource

func AddFileSource(path string)

AddFileSource adds a file configuration source.

func AddFolder

func AddFolder(dirs ...string)

AddFolder adds directories to searching list.

func AddSource

func AddSource(srcs ...Source)

AddSource adds custom configuration sources.

func BindEnv

func BindEnv(key string, envKey string)

BindEnv binds a option to an environment variable.

func BindFlags

func BindFlags(set *flag.FlagSet)

BindFlags binds a flag set.

func Exist

func Exist(key string) bool

Exist returns the key is existed or not.

func FindFile

func FindFile(name string, exts ...string) string

FindFile searches all config directories and return the first found file.

func FindFiles

func FindFiles(name string, exts ...string) []string

FindFiles searches all config directories and return all found files.

func FindFolder

func FindFolder(name string) string

FindFolder searches all config directories and return the first found folder.

func FindFolders

func FindFolders(name string) []string

FindFolders searches all config directories and return all found folders.

func Get

func Get(key string) interface{}

Get searches option from flag/env/config/remote/default. It returns nil if option is not found.

func GetBool

func GetBool(key string) bool

GetBool returns option as bool.

func GetDuration

func GetDuration(key string) time.Duration

GetDuration returns option as time.Duration.

func GetInt

func GetInt(key string) int

GetInt returns option as int.

func GetInt16

func GetInt16(key string) int16

GetInt16 returns option as int16.

func GetInt32

func GetInt32(key string) int32

GetInt32 returns option as int32.

func GetInt64

func GetInt64(key string) int64

GetInt64 returns option as int64.

func GetInt8

func GetInt8(key string) int8

GetInt8 returns option as int8.

func GetString

func GetString(key string) string

GetString returns option as string.

func GetTime

func GetTime(key string) time.Time

GetTime returns option as time.Time.

func GetUint

func GetUint(key string) uint

GetUint returns option as uint.

func GetUint16

func GetUint16(key string) uint16

GetUint16 returns option as uint16.

func GetUint32

func GetUint32(key string) uint32

GetUint32 returns option as uint32.

func GetUint64

func GetUint64(key string) uint64

GetUint64 returns option as uint64.

func GetUint8

func GetUint8(key string) uint8

GetUint8 returns option as uint8.

func Load

func Load() error

Load reads options from all sources.

func SetDefaultValue

func SetDefaultValue(name string, value interface{})

SetDefaultValue sets a default option.

func SetEnvPrefix

func SetEnvPrefix(prefix string)

SetEnvPrefix sets the prefix of environment variables. Default prefix is "AUXO".

func SetName

func SetName(name string)

SetName sets name of the main configuration file (without extension).

func SetProfile

func SetProfile(profiles ...string)

SetProfile sets active profiles. Profiles are only valid to local file sources.

func Unmarshal

func Unmarshal(v interface{}) error

Unmarshal exports options to struct.

func UnmarshalOption

func UnmarshalOption(name string, v interface{}) error

UnmarshalOption exports specific option to struct.

Types

type Manager

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

func New

func New(name ...string) *Manager

func (*Manager) AddDataSource

func (m *Manager) AddDataSource(data []byte, ct string)

AddDataSource add a config source with bytes and type.

func (*Manager) AddFileSource

func (m *Manager) AddFileSource(path string)

AddFileSource adds a file configuration source.

func (*Manager) AddFolder

func (m *Manager) AddFolder(dirs ...string)

AddFolder adds directories to searching list.

func (*Manager) AddSource

func (m *Manager) AddSource(srcs ...Source)

AddSource adds custom configuration sources.

func (*Manager) BindEnv

func (m *Manager) BindEnv(key string, envKey string)

BindEnv binds a option to an environment variable.

func (*Manager) BindFlags

func (m *Manager) BindFlags(set *flag.FlagSet)

BindFlags binds a flag set.

func (*Manager) FindFile

func (m *Manager) FindFile(name string, exts ...string) string

FindFile searches all config directories and return the first found file.

func (*Manager) FindFiles

func (m *Manager) FindFiles(name string, exts ...string) []string

FindFiles searches all config directories and return all found files.

func (*Manager) FindFolder

func (m *Manager) FindFolder(name string) string

FindFolder searches all config directories and return the first found folder.

func (*Manager) FindFolders

func (m *Manager) FindFolders(name string) []string

FindFolders searches all config directories and return all found folders.

func (*Manager) Get

func (m *Manager) Get(key string) interface{}

Get searches option from flag/env/config/remote/default. It returns nil if option is not found.

func (*Manager) GetBool

func (m *Manager) GetBool(key string) bool

GetBool returns option as bool.

func (*Manager) GetDuration

func (m *Manager) GetDuration(key string) time.Duration

GetDuration returns option as time.Duration.

func (*Manager) GetInt

func (m *Manager) GetInt(key string) int

GetInt returns option as int.

func (*Manager) GetInt16

func (m *Manager) GetInt16(key string) int16

GetInt16 returns option as int16.

func (*Manager) GetInt32

func (m *Manager) GetInt32(key string) int32

GetInt32 returns option as int32.

func (*Manager) GetInt64

func (m *Manager) GetInt64(key string) int64

GetInt64 returns option as int64.

func (*Manager) GetInt8

func (m *Manager) GetInt8(key string) int8

GetInt8 returns option as int8.

func (*Manager) GetString

func (m *Manager) GetString(key string) string

GetString returns option as string.

func (*Manager) GetTime

func (m *Manager) GetTime(key string) time.Time

GetTime returns option as time.Time.

func (*Manager) GetUint

func (m *Manager) GetUint(key string) uint

GetInt returns option as uint.

func (*Manager) GetUint16

func (m *Manager) GetUint16(key string) uint16

GetInt16 returns option as uint16.

func (*Manager) GetUint32

func (m *Manager) GetUint32(key string) uint32

GetInt32 returns option as uint32.

func (*Manager) GetUint64

func (m *Manager) GetUint64(key string) uint64

GetInt64 returns option as uint64.

func (*Manager) GetUint8

func (m *Manager) GetUint8(key string) uint8

GetInt8 returns option as uint8.

func (*Manager) Load

func (m *Manager) Load() error

Load reads options from all sources.

func (*Manager) SetDefaultValue

func (m *Manager) SetDefaultValue(name string, value interface{})

SetDefaultValue sets a default option.

func (*Manager) SetEnvPrefix

func (m *Manager) SetEnvPrefix(prefix string)

SetEnvPrefix sets the prefix of environment variables. Default prefix is "AUXO".

func (*Manager) SetName

func (m *Manager) SetName(name string)

SetName sets name of the main configuration file (without extension).

func (*Manager) SetProfile

func (m *Manager) SetProfile(profiles ...string)

SetProfile sets active profiles. Profiles are only valid to local file sources.

func (*Manager) Unmarshal

func (m *Manager) Unmarshal(v interface{}) error

Unmarshal exports options to struct.

func (*Manager) UnmarshalOption

func (m *Manager) UnmarshalOption(name string, v interface{}) error

UnmarshalOption exports specific option to struct.

type Source

type Source interface {
	Load() (data.Map, error)
}

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(i interface{}) error
}

Unmarshaler is custom unmarshal interface for Config.Unmarshal method.

Jump to

Keyboard shortcuts

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