Documentation
¶
Index ¶
- func Load[P ~*T, T any](options ...Option) (P, string, error)
- type ConfigOptions
- type Extension
- type FileType
- type MockStorage
- func (m *MockStorage) All(ctx context.Context) (map[string]any, error)
- func (m *MockStorage) Delete(ctx context.Context, key string) error
- func (m *MockStorage) EXPECT() *MockStorageMockRecorder
- func (m *MockStorage) Get(ctx context.Context, key string) (any, error)
- func (m *MockStorage) Set(ctx context.Context, key string, val any) error
- type MockStorageAllCall
- type MockStorageDeleteCall
- type MockStorageGetCall
- type MockStorageMockRecorder
- type MockStorageSetCall
- type Option
- func WithContext(val context.Context) Option
- func WithExtension(ext string, fileType FileType) Option
- func WithExtensions(val []Extension) Option
- func WithFile(val string) Option
- func WithFlags(val *flags.Flags) Option
- func WithIndex(val index.Index) Option
- func WithName(val string) Option
- func WithParserHooks(hooks ...lookup.ParserHook) Option
- func WithPaths(val ...string) Option
- func WithReplacer(m map[string]string) Option
- func WithStorage(val Storage) Option
- func WithWorkingDir(val bool) Option
- func WithWorldWritable(val bool) Option
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConfigOptions ¶
type ConfigOptions struct {
File string
FileType FileType
Storage Storage
Name string
Paths []string
Strict bool
Index index.Index
Flags *flags.Flags
Extensions []Extension
Replacer map[string]string
Hooks []lookup.ParserHook
WorkingDir bool
WorldWritable bool
// contains filtered or unexported fields
}
type MockStorage ¶ added in v1.2.0
type MockStorage struct {
// contains filtered or unexported fields
}
MockStorage is a mock of Storage interface.
func NewMockStorage ¶ added in v1.2.0
func NewMockStorage(ctrl *gomock.Controller) *MockStorage
NewMockStorage creates a new mock instance.
func (*MockStorage) Delete ¶ added in v1.3.0
func (m *MockStorage) Delete(ctx context.Context, key string) error
Delete mocks base method.
func (*MockStorage) EXPECT ¶ added in v1.2.0
func (m *MockStorage) EXPECT() *MockStorageMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockStorageAllCall ¶ added in v1.2.0
MockStorageAllCall wrap *gomock.Call
func (*MockStorageAllCall) Do ¶ added in v1.2.0
func (c *MockStorageAllCall) Do(f func(context.Context) (map[string]any, error)) *MockStorageAllCall
Do rewrite *gomock.Call.Do
func (*MockStorageAllCall) DoAndReturn ¶ added in v1.2.0
func (c *MockStorageAllCall) DoAndReturn(f func(context.Context) (map[string]any, error)) *MockStorageAllCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockStorageAllCall) Return ¶ added in v1.2.0
func (c *MockStorageAllCall) Return(arg0 map[string]any, arg1 error) *MockStorageAllCall
Return rewrite *gomock.Call.Return
type MockStorageDeleteCall ¶ added in v1.3.0
MockStorageDeleteCall wrap *gomock.Call
func (*MockStorageDeleteCall) Do ¶ added in v1.3.0
func (c *MockStorageDeleteCall) Do(f func(context.Context, string) error) *MockStorageDeleteCall
Do rewrite *gomock.Call.Do
func (*MockStorageDeleteCall) DoAndReturn ¶ added in v1.3.0
func (c *MockStorageDeleteCall) DoAndReturn(f func(context.Context, string) error) *MockStorageDeleteCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockStorageDeleteCall) Return ¶ added in v1.3.0
func (c *MockStorageDeleteCall) Return(arg0 error) *MockStorageDeleteCall
Return rewrite *gomock.Call.Return
type MockStorageGetCall ¶ added in v1.2.0
MockStorageGetCall wrap *gomock.Call
func (*MockStorageGetCall) Do ¶ added in v1.2.0
func (c *MockStorageGetCall) Do(f func(context.Context, string) (any, error)) *MockStorageGetCall
Do rewrite *gomock.Call.Do
func (*MockStorageGetCall) DoAndReturn ¶ added in v1.2.0
func (c *MockStorageGetCall) DoAndReturn(f func(context.Context, string) (any, error)) *MockStorageGetCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockStorageGetCall) Return ¶ added in v1.2.0
func (c *MockStorageGetCall) Return(arg0 any, arg1 error) *MockStorageGetCall
Return rewrite *gomock.Call.Return
type MockStorageMockRecorder ¶ added in v1.2.0
type MockStorageMockRecorder struct {
// contains filtered or unexported fields
}
MockStorageMockRecorder is the mock recorder for MockStorage.
func (*MockStorageMockRecorder) All ¶ added in v1.2.0
func (mr *MockStorageMockRecorder) All(ctx any) *MockStorageAllCall
All indicates an expected call of All.
func (*MockStorageMockRecorder) Delete ¶ added in v1.3.0
func (mr *MockStorageMockRecorder) Delete(ctx, key any) *MockStorageDeleteCall
Delete indicates an expected call of Delete.
func (*MockStorageMockRecorder) Get ¶ added in v1.2.0
func (mr *MockStorageMockRecorder) Get(ctx, key any) *MockStorageGetCall
Get indicates an expected call of Get.
func (*MockStorageMockRecorder) Set ¶ added in v1.2.0
func (mr *MockStorageMockRecorder) Set(ctx, key, val any) *MockStorageSetCall
Set indicates an expected call of Set.
type MockStorageSetCall ¶ added in v1.2.0
MockStorageSetCall wrap *gomock.Call
func (*MockStorageSetCall) Do ¶ added in v1.2.0
func (c *MockStorageSetCall) Do(f func(context.Context, string, any) error) *MockStorageSetCall
Do rewrite *gomock.Call.Do
func (*MockStorageSetCall) DoAndReturn ¶ added in v1.2.0
func (c *MockStorageSetCall) DoAndReturn(f func(context.Context, string, any) error) *MockStorageSetCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockStorageSetCall) Return ¶ added in v1.2.0
func (c *MockStorageSetCall) Return(arg0 error) *MockStorageSetCall
Return rewrite *gomock.Call.Return
type Option ¶
type Option interface {
Set(*ConfigOptions)
}
var Strict Option = optionFunc(func(o *ConfigOptions) { o.Strict = true })
Strict makes Load fail on environment variables with the name prefix (see WithName) that don't match a field, instead of ignoring them.
func WithContext ¶ added in v1.3.0
func WithExtension ¶
WithExtension restricts the config file search, including $CONFIG, to a single extension and file type. It replaces any earlier extension options but doesn't affect a file given with WithFile.
func WithExtensions ¶
WithExtensions sets the extensions and file types accepted by the config file search, including $CONFIG. It replaces any earlier extension options but doesn't affect a file given with WithFile.
func WithFile ¶
WithFile sets the config file to load and disables the search for one, including $CONFIG. The type is taken from the extension (.json, .yaml or .yml) and a path with a ".." element is rejected.
func WithFlags ¶
WithFlags applies the bound command-line flags that were set by the user. They are applied last, so they override all other sources.
func WithIndex ¶
WithIndex sets the index that maps environment variable names to field paths. Without it, the index is built from the config struct, so this is only needed for custom mappings.
func WithName ¶
WithName sets the base name of the config file (default "config") and the prefix of environment variables, e.g. "my-app" reads MY_APP_HOST. Environment variables are only read when a name is set.
func WithParserHooks ¶ added in v1.5.0
func WithParserHooks(hooks ...lookup.ParserHook) Option
WithParserHooks parses the values of the storage, the environment and the flags into types the parser doesn't know, such as an interface type. It adds to the hooks of an earlier WithParserHooks.
func WithPaths ¶
WithPaths sets the directories searched for a config file before the working directory (see WithWorkingDir) and the home directory. It replaces the paths of an earlier WithPaths.
func WithReplacer ¶
WithReplacer replaces parts of field names when the environment variable names are built, e.g. {"Sub": "Section"} maps Sub.Name to SECTION_NAME. It has no effect together with WithIndex.
func WithStorage ¶ added in v1.2.0
WithStorage merges all values from val after the config file and before environment variables. Load calls only val.All(); keys are lower-case, dot-separated field paths such as "sub.name".
func WithWorkingDir ¶ added in v1.2.0
WithWorkingDir adds the working directory to the config file search, between the WithPaths directories and the home directory. It is off by default, because a file in an untrusted directory would change the settings.
func WithWorldWritable ¶ added in v1.2.0
WithWorldWritable allows config files that are writable by others. They are rejected by default, because anybody could change them. It has no effect on Windows.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
cobra
command
|
|
|
cobra-autobinding
command
|
|
|
env-list
command
|
|
|
pflags
command
|
|
|
pkg
|
|
|
errors
Package errors keeps configuration values out of error messages, because values can be secrets that would otherwise end up in logs.
|
Package errors keeps configuration values out of error messages, because values can be secrets that would otherwise end up in logs. |