Documentation ¶
Overview ¶
Package appext contains functionality to work with flags.
Index ¶
- func Listen(ctx context.Context, container NameContainer, defaultPort uint16) (net.Listener, error)
- func ReadConfig(container NameContainer, value interface{}) error
- func ReadSecret(container NameContainer, name string) (string, error)
- func WriteConfig(container NameContainer, value interface{}) error
- type Builder
- type BuilderOption
- type Container
- type Interceptor
- type LoggerContainer
- type NameContainer
- type SubCommandBuilder
- type TracerContainer
- type VerboseContainer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadConfig ¶
func ReadConfig(container NameContainer, value interface{}) error
ReadConfig reads the configuration from the YAML configuration file config.yaml in the configuration directory.
If the file does not exist, this is a no-op. The value should be a pointer to unmarshal into.
func ReadSecret ¶
func ReadSecret(container NameContainer, name string) (string, error)
ReadSecret returns the contents of the file at path filepath.Join(container.ConfigDirPath(), secretRelDirPath, name).
func WriteConfig ¶
func WriteConfig(container NameContainer, value interface{}) error
WriteConfig writes the configuration to the YAML configuration file config.yaml in the configuration directory.
The directory is created if it does not exist. The value should be a pointer to marshal.
Types ¶
type Builder ¶
type Builder interface { BindRoot(flagSet *pflag.FlagSet) SubCommandBuilder }
Builder builds run functions for both top-level commands and sub-commands.
func NewBuilder ¶
func NewBuilder(appName string, options ...BuilderOption) Builder
NewBuilder returns a new Builder.
type BuilderOption ¶
type BuilderOption func(*builder)
BuilderOption is an option for a new Builder
func BuilderWithDefaultLogLevel ¶
func BuilderWithDefaultLogLevel(defaultLogLevel zapcore.Level) BuilderOption
BuilderWithDefaultLogLevel adds the given default log level.
func BuilderWithInterceptor ¶
func BuilderWithInterceptor(interceptor Interceptor) BuilderOption
BuilderWithInterceptor adds the given interceptor for all run functions.
func BuilderWithTimeout ¶
func BuilderWithTimeout(defaultTimeout time.Duration) BuilderOption
BuilderWithTimeout returns a new BuilderOption that adds a timeout flag and the default timeout.
func BuilderWithTracing ¶
func BuilderWithTracing() BuilderOption
BuilderWithTracing enables zap tracing for the builder.
type Container ¶
type Container interface { app.Container NameContainer LoggerContainer TracerContainer VerboseContainer }
Container contains not just the base app container, but all extended containers.
type Interceptor ¶
type Interceptor func(func(context.Context, Container) error) func(context.Context, Container) error
Interceptor intercepts and adapts the request or response of run functions.
type LoggerContainer ¶
LoggerContainer provides a *zap.Logger.
func NewLoggerContainer ¶
func NewLoggerContainer(logger *zap.Logger) LoggerContainer
NewLoggerContainer returns a new LoggerContainer.
type NameContainer ¶
type NameContainer interface { // AppName is the application name. // // The name must be in [a-zA-Z0-9-_]. AppName() string // ConfigDirPath is the config directory path for the named application. // // First checks for $APP_NAME_CONFIG_DIR. // If this is not set, uses app.ConfigDirPath()/app-name. // Unnormalized. ConfigDirPath() string // CacheDirPath is the cache directory path for the named application. // // First checks for $APP_NAME_CACHE_DIR. // If this is not set, uses app.CacheDirPath()/app-name. // Unnormalized. CacheDirPath() string // DataDirPath is the data directory path for the named application. // // First checks for $APP_NAME_DATA_DIR. // If this is not set, uses app.DataDirPath()/app-name. // Unnormalized. DataDirPath() string // Port is the port to use for serving. // // First checks for $APP_NAME_PORT. // If this is not set, checks for $PORT. // If this is not set, returns 0, which means no port is known. // Returns error on parse. Port() (uint16, error) }
NameContainer is a container for named applications.
Application name foo-bar translates to environment variable prefix FOO_BAR_, which is used for the various functions that NameContainer provides.
func NewNameContainer ¶
func NewNameContainer(envContainer app.EnvContainer, appName string) (NameContainer, error)
NewNameContainer returns a new NameContainer.
The name must be in [a-zA-Z0-9-_].
type SubCommandBuilder ¶
type SubCommandBuilder interface {
NewRunFunc(func(context.Context, Container) error) func(context.Context, app.Container) error
}
SubCommandBuilder builds run functions for sub-commands.
type TracerContainer ¶
TracerContainer provides a trace.Tracer based on the application name.
func NewTracerContainer ¶
func NewTracerContainer(appName string) TracerContainer
NewTracerContainer returns a new TracerContainer for the application name.
type VerboseContainer ¶
type VerboseContainer interface { // VerboseEnabled returns true if verbose mode is enabled. VerboseEnabled() bool // VerbosePrinter returns a verbose.Printer to use for verbose printing. VerbosePrinter() verbose.Printer }
VerboseContainer provides a verbose.Printer.
func NewVerboseContainer ¶
func NewVerboseContainer(verbosePrinter verbose.Printer) VerboseContainer
NewVerboseContainer returns a new VerboseContainer.