option

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOption

type ClientOption interface {
	Apply(*Options)
}

func WithCustomExternalInjection added in v1.4.5

func WithCustomExternalInjection(f func(string) (string, ConfigSource)) ClientOption

func WithCustomUsage

func WithCustomUsage() ClientOption

WithCustomUsage generates usage for -help flag from input struct. By default EnvConf uses this function. Use `option.WithoutCustomUsage` to disable it

func WithExternal added in v1.4.0

func WithExternal(e external.External) ClientOption

func WithExternalInjection added in v1.4.5

func WithExternalInjection() ClientOption

WithExternalInjection allows to inject variables from an external source use format ${ .env.<ENV_VAR_NAME> } to make an env variable lookup while getting a field from the external source

func WithFlagConfigFile added in v1.4.0

func WithFlagConfigFile(flagName string, flagValue string, flagDescription string, initConf func([]byte) (external.External, error)) ClientOption

WithFlagConfigFile wraps option.WithFlagParsed with reading configuration file from flag defined path

func WithFlagParsed

func WithFlagParsed(flagParsed func() error) ClientOption

WithFlagParsed define this callback when you need handle flags This callback will raise after method flag.Parse() return not nil error interrupt pasring

func WithPriorityOrder

func WithPriorityOrder(s ...ConfigSource) ClientOption

WithPriorityOrder overrides default priority order, with an order from function argument. Default priority order is: Flag, Environment variable, External source, Default value.

func WithoutCustomUsage

func WithoutCustomUsage() ClientOption

type ConfigSource

type ConfigSource int
const (
	NoConfigValue ConfigSource = -1
	FlagVariable  ConfigSource = 1 << (iota - 1)
	EnvVariable
	ExternalSource
	DefaultValue
)

func (ConfigSource) String

func (s ConfigSource) String() string

type FieldDefineErrorArg

type FieldDefineErrorArg struct {
	Name     string
	FullName string
	Type     reflect.Type
	Err      error
}

type FieldDefinedArg

type FieldDefinedArg struct {
	Name        string
	FullName    string
	Type        reflect.Type
	Required    bool
	Description string

	FlagName     string
	EnvName      string
	DefaultValue interface{}

	Source ConfigSource
	Value  interface{}
}

type FieldInitializedArg

type FieldInitializedArg struct {
	Name        string
	FullName    string
	Type        reflect.Type
	Required    bool
	Description string

	FlagName     string
	EnvName      string
	DefaultValue interface{}
}

type Logger

type Logger struct {
	Printer
	// Enable secrets hide
	HideSecrets bool
	// Regex for match secrets by field name in lower case
	SecretMatchRegex string
}

func WithLog

func WithLog(p Printer) *Logger

SetLogger define printer. This logger will print defined values and errors to Printer.Print method. By Default all secrets will be hidden

func (*Logger) Apply

func (l *Logger) Apply(opts *Options)

type Options

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

func (*Options) External added in v1.4.0

func (o *Options) External() external.External

func (*Options) ExternalInjection added in v1.4.5

func (o *Options) ExternalInjection() func(string) (string, ConfigSource)

func (*Options) FlagParsed

func (o *Options) FlagParsed() func() error

func (*Options) OnFieldDefineErr

func (o *Options) OnFieldDefineErr(arg FieldDefineErrorArg)

func (*Options) OnFieldDefined

func (o *Options) OnFieldDefined(arg FieldDefinedArg)

func (*Options) OnFieldInitialized

func (o *Options) OnFieldInitialized(arg FieldInitializedArg)

func (*Options) PriorityOrder

func (o *Options) PriorityOrder() []ConfigSource

func (*Options) Usage

func (o *Options) Usage() func()

type Printer

type Printer interface {
	Print(...interface{})
}

Jump to

Keyboard shortcuts

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