Documentation
¶
Index ¶
- Constants
- type CLI
- func (c *CLI) Bool(name, shorthand string, defaultValue bool, usage string) *CLI
- func (c *CLI) Duration(name, shorthand string, duration time.Duration, usage string) *CLI
- func (c *CLI) Float(name, shorthand string, defaultValue float64, usage string) *CLI
- func (c *CLI) FromStruct(v interface{}) *CLI
- func (c *CLI) Get(name string) interface{}
- func (c *CLI) GetBool(name string) bool
- func (c *CLI) GetDuration(name string) time.Duration
- func (c *CLI) GetFloat(name string) float64
- func (c *CLI) GetInt(name string) int
- func (c *CLI) GetString(name string) string
- func (c *CLI) Int(name, shorthand string, defaultValue int, usage string) *CLI
- func (c *CLI) LoadConfig(path string, v interface{}) error
- func (c *CLI) MustParse() *CLI
- func (c *CLI) Okapi() *okapi.Okapi
- func (c *CLI) Parse() error
- func (c *CLI) ParseFlags() error
- func (c *CLI) Run() error
- func (c *CLI) RunServer(opts ...*RunOptions) error
- func (c *CLI) String(name, shorthand, defaultValue, usage string) *CLI
- func (c *CLI) WithConfig(cfg interface{}) *CLI
- type RunOptions
Constants ¶
const ( // SIGINT is the interrupt signal SIGINT = syscall.SIGINT // SIGTERM is the termination signal SIGTERM = syscall.SIGTERM )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
func Default ¶ added in v0.3.5
func Default() *CLI
Default creates a CLI manager with a default Okapi instance
func New ¶
New creates a new CLI manager for the Okapi You can optionally provide a custom application name
func (*CLI) FromStruct ¶ added in v0.3.5
FromStruct registers CLI flags from struct tags. Supported tags:
- cli: flag name (required to register flag)
- short: shorthand letter (optional)
- desc: description text (optional)
- env: environment variable name to read from (optional)
- default: default value (optional; otherwise uses field's current value)
Supported types: string, int*, bool, float*
func (*CLI) GetDuration ¶ added in v0.3.5
GetDuration retrieves a time.Duration flag value
func (*CLI) LoadConfig ¶
LoadConfig loads configuration from a JSON or YAML file into a struct.
func (*CLI) Run ¶
Run starts Okapi using default options and waits for shutdown signals. It handles graceful shutdown automatically.
It is a shortcut for RunServer(nil)
func (*CLI) RunServer ¶
func (c *CLI) RunServer(opts ...*RunOptions) error
RunServer starts Okapi and waits for shutdown signals. It handles graceful shutdown automatically
func (*CLI) WithConfig ¶ added in v0.3.5
WithConfig registers CLI flags from struct tags. Supported tags:
- cli: flag name (required to register flag)
- short: shorthand letter (optional)
- desc: description text (optional)
- env: environment variable name to read from (optional)
- default: default value (optional; otherwise uses field's current value)
Supported types: string, int*, bool, float*
type RunOptions ¶
type RunOptions struct {
// ShutdownTimeout is the maximum time to wait for graceful shutdown
ShutdownTimeout time.Duration
// Signals are the OS signals to listen for (defaults to SIGINT, SIGTERM)
Signals []os.Signal
// OnStart is called right before the server starts
OnStart func()
// OnStarted is called after the server starts successfully
OnStarted func()
// OnShutdown is called before shutdown begins
OnShutdown func()
}
RunOptions configures the Run behavior