app

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: MIT Imports: 29 Imported by: 1

README

App Flags

The application supports the following configuration flags:

Main Server Configuration

Flag Environment Variable Description Default Value
--main-ep-addr MAIN_ENTRYPOINT_ADDR Main entrypoint address to listen on :8080
--main-ep-net-keep-alive MAIN_ENTRYPOINT_NET_KEEP_ALIVE Main entrypoint keep alive 0
--main-ep-http-read-timeout MAIN_ENTRYPOINT_HTTP_READ_TIMEOUT Main entrypoint maximum duration for reading an entire request including the body (zero means no timeout) 30s
--main-ep-http-read-header-timeout MAIN_READ_HEADER_TIMEOUT Main entrypoint maximum duration for reading request headers (zero uses the value of read timeout) 30s
--main-ep-http-write-timeout MAIN_ENTRYPOINT_HTTP_WRITE_TIMEOUT Main entrypoint maximum duration for writing the response (zero means no timeout) 30s
--main-ep-http-idle-timeout MAIN_ENTRYPOINT_HTTP_IDLE_TIMEOUT Main entrypoint maximum amount of time to wait for the next request when keep-alives are enabled (zero uses the value of read timeout) 30s

Health Check Server Configuration

Flag Environment Variable Description Default Value
--healthz-ep-addr HEALTHZ_ENTRYPOINT_ADDR Health check entrypoint address :8081
--healthz-ep-keep-alive HEALTHZ_ENTRYPOINT_NET_KEEP_ALIVE Health check entrypoint keep alive 0
--healthz-ep-http-read-timeout HEALTHZ_NTRYPOINT_HTTP_READ_TIMEOUT Health entrypoint maximum duration for reading an entire request including the body (zero means no timeout) 30s
--healthz-ep-http-read-header-timeout HEALTHZ_NTRYPOINT_HTTP_READ_HEADER_TIMEOUT Health entrypoint maximum duration for reading request headers (zero uses the value of read timeout) 30s
--healthz-ep-http-write-timeout HEALTHZ_NTRYPOINT_HTTP_WRITE_TIMEOUT Health entrypoint maximum duration for writing the response (zero means no timeout) 30s
--healthz-ep-http-idle-timeout HEALTHZ_NTRYPOINT_HTTP_IDLE_TIMEOUT Health entrypoint maximum amount of time to wait for the next request when keep-alives are enabled (zero uses the value of read timeout) 30s

All configuration flags can be set via command-line arguments, environment variables, or through a configuration file. The application uses Viper for configuration management, which supports multiple configuration formats.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(v *viper.Viper, f *pflag.FlagSet) error

AddFlags adds flags to the given viper and pflag.FlagSet.

func Provide

func Provide[T any](app *App, id string, constructor func() (T, error), opts ...ServiceOption) T

Types

type App

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

func NewApp

func NewApp(cfg *Config, opts ...Option) (*App, error)

func (*App) Context added in v0.4.1

func (app *App) Context(ctx context.Context) context.Context

func (*App) EnableHealthzEntrypoint

func (app *App) EnableHealthzEntrypoint()

func (*App) EnableMainEntrypoint

func (app *App) EnableMainEntrypoint()

func (*App) Error

func (app *App) Error() error

func (*App) Provide

func (app *App) Provide(id string, constructor func() (any, error), opts ...ServiceOption) any

func (*App) Run

func (app *App) Run(ctx context.Context) error

func (*App) Start

func (app *App) Start(ctx context.Context) error

func (*App) Stop

func (app *App) Stop(ctx context.Context) error

type Config

type Config struct {
	MainEntrypoint    *kkrthttp.EntrypointConfig `key:"main-ep" env:"MAIN_EP" flag:"main-ep" desc:"main entrypoint: "`
	HealthzEntrypoint *kkrthttp.EntrypointConfig `key:"healthz-ep" env:"HEALTHZ_EP" flag:"healthz-ep" desc:"healthz entrypoint: "`
	Log               *log.Config                `key:"log"`
	StartTimeout      *string                    `key:"start-timeout" env:"START_TIMEOUT" flag:"start-timeout" desc:"Start timeout"`
	StopTimeout       *string                    `key:"stop-timeout" env:"STOP_TIMEOUT" flag:"stop-timeout" desc:"Stop timeout"`
}

Config is the configuration for the application.

func DefaultConfig added in v0.3.5

func DefaultConfig() *Config

func (*Config) Env added in v0.3.5

func (cfg *Config) Env() (map[string]string, error)

Env returns the environment variables for the given Config.

func (*Config) Unmarshal added in v0.3.5

func (cfg *Config) Unmarshal(v *viper.Viper) error

Unmarshal unmarshals the given viper into the Config.

type Option

type Option func(*App) error

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the logger of the application.

func WithName

func WithName(name string) Option

WithAppName sets the name of the application.

func WithVersion

func WithVersion(version string) Option

WithVersion sets the version of the application.

type ServiceError

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

func (*ServiceError) Error

func (e *ServiceError) Error() string

type ServiceOption

type ServiceOption func(*service) error

func WithComponentName

func WithComponentName(name string) ServiceOption

WithComponentName sets the name of the component. Multiple services can have the same component name. By default, the component name is the name of the service identifier which is unique. This enables to override the default name (without unicity constraints)

func WithHealthConfig

func WithHealthConfig(cfg *health.Config) ServiceOption

WithHealthConfig sets the health config of the service.

func WithTags

func WithTags(tags ...*tag.Tag) ServiceOption

WithTags sets the tags of the service.

type ServiceStatus

type ServiceStatus uint32
const (
	Constructing ServiceStatus = iota
	Constructed
	Starting
	Running
	Stopping
	Stopped
	Error
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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