application

package
v0.0.0-...-a3f3b02 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultOsReloadSignals   = []os.Signal{syscall.SIGHUP}
	DefaultOsShutdownSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT}
	DefaultShutdownTimeout   = time.Second * 2

	DefaultSignals = &Signals{
		shutdownSignals:         DefaultOsShutdownSignals,
		shutdownFunc:            nil,
		gracefulShutdown:        true,
		gracefulShutdownTimeout: DefaultShutdownTimeout,
		reloadSignals:           DefaultOsReloadSignals,
		customSignals:           nil,
		mux:                     &sync.RWMutex{},
	}

	ErrReload = errors.New("reload requested")
)

Shutdown configuration

Functions

func NewCommand

func NewCommand(name string) *command

func NewComponent

func NewComponent(name string, t reflect.Type) *component

Types

type App

type App interface {
	Execute(args []string)
	Log() *slogd.Logger
	Name() string
	Pid() int
}

type Builder

type Builder struct {
	Title   string
	Version Version
	Command *command
	Signals *Signals
	Mux     *sync.Mutex
}

func (Builder) Build

func (b Builder) Build() App

type Component

type Component interface {
	Name() string
	Type() reflect.Type
	WithPreRunE(f func(ctx Context) error) Component
	WithPostRunE(f func(ctx Context) error) Component
	PreRunE() func(ctx Context) error
	PostRunE() func(ctx Context) error
	Get() any
	Set(v any)
}

type Context

type Context struct {
	Ctx context.Context
	App *app
}

func (Context) Args

func (c Context) Args() []string

func (Context) Flag

func (c Context) Flag(name string) any

func (Context) FlagBool

func (c Context) FlagBool(name string) bool

func (Context) FlagDuration

func (c Context) FlagDuration(name string) time.Duration

func (Context) FlagFloat64

func (c Context) FlagFloat64(name string) float64

func (Context) FlagInt

func (c Context) FlagInt(name string) int

func (Context) FlagInt64

func (c Context) FlagInt64(name string) int64

func (Context) FlagString

func (c Context) FlagString(name string) string

func (Context) GetComponent

func (c Context) GetComponent(name string, t reflect.Type) (Component, error)

func (Context) SetComponent

func (c Context) SetComponent(component Component) error

type Flag

type Flag struct {
	Name     string
	Short    string // single-char alias (e.g. "p")
	Usage    string
	Default  any // must match FlagType
	Type     FlagType
	Allowed  []any // optional list of allowed values; checked when Validate is nil
	Required bool
	Validate func(any) error // optional per-flag value validator
}

type FlagType

type FlagType int
const (
	FlagString FlagType = iota
	FlagInt
	FlagInt64
	FlagFloat64
	FlagBool
	FlagDuration
)

type Signal

type Signal struct {
	Signal  os.Signal
	Handler func(ctx Context, cancel context.CancelFunc, sig os.Signal) error
}

type Signals

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

func NewSignals

func NewSignals() *Signals

func (*Signals) CustomSignals

func (s *Signals) CustomSignals() []os.Signal

func (*Signals) Handler

func (s *Signals) Handler(signal os.Signal) func(ctx Context, cancel context.CancelFunc, sig os.Signal) error

func (*Signals) ReloadFunc

func (s *Signals) ReloadFunc(ctx Context, cancel context.CancelFunc) error

func (*Signals) ReloadSignals

func (s *Signals) ReloadSignals() []os.Signal

func (*Signals) ShutdownFunc

func (s *Signals) ShutdownFunc(ctx Context, cancel context.CancelFunc, chRun chan error) (err error)

func (*Signals) ShutdownSignals

func (s *Signals) ShutdownSignals() []os.Signal

func (*Signals) WithCustomSignal

func (s *Signals) WithCustomSignal(signal Signal) *Signals

func (*Signals) WithReloadOverride

func (s *Signals) WithReloadOverride(signals []os.Signal, reloadFunc func(ctx Context, cancel context.CancelFunc) error) *Signals

func (*Signals) WithShutdownOverride

func (s *Signals) WithShutdownOverride(signals []os.Signal, shutdownFunc func(ctx Context, cancel context.CancelFunc, chRun chan error) error) *Signals

type Version

type Version struct {
	Full       string
	Branch     string
	Tag        string
	Commit     string
	CommitDate string
	BuildDate  string
	Major      string
	Minor      string
	Patch      string
	Prerelease string
}

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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