Documentation ¶
Overview ¶
Package happy provides a modular framework for rapid prototyping in Go. With this SDK, developers of all levels can easily bring their ideas to life. Whether you're a hacker or a creator, Package happy has everything you need to tackle your domain problems and create working prototypes or MVPs with minimal technical knowledge and infrastructure planning.
Its modular design enables you to package your commands and services into reusable addons, so you're not locked into any vendor tools. It also fits well into projects where different components are written in different programming languages.
Let Package happy help you bring your projects from concept to reality and make you happy along the way.
Index ¶
- Variables
- func GetAPI[A API](sess *Session, addonName string) (api A, err error)
- type API
- type Action
- type ActionMigrate
- type ActionTick
- type ActionTock
- type ActionWithArgs
- type ActionWithEvent
- type ActionWithOptions
- type Addon
- func (addon *Addon) Emits(scope, key, description string, example *vars.Map)
- func (addon *Addon) EmitsEvent(event Event)
- func (addon *Addon) OnRegister(action ActionWithOptions)
- func (addon *Addon) ProvidesCommand(cmd *Command)
- func (addon *Addon) ProvidesService(svc *Service)
- func (addon *Addon) Setting(key string, value any, description string, validator OptionValueValidator)
- type AddonInfo
- type Application
- func (a *Application) AddCommand(cmd *Command)
- func (a *Application) AddFlag(f varflag.Flag)
- func (a *Application) AfterAlways(action Action)
- func (a *Application) AfterFailure(action func(s *Session, err error) error)
- func (a *Application) AfterSuccess(action Action)
- func (a *Application) Before(action ActionWithArgs)
- func (a *Application) Cron(setup func(schedule CronScheduler))
- func (a *Application) Do(action ActionWithArgs)
- func (a *Application) Main()
- func (a *Application) OnInstall(action Action)
- func (a *Application) OnMigrate(ver string, up, down ActionMigrate)
- func (a *Application) OnTick(action ActionTick)
- func (a *Application) OnTock(action ActionTock)
- func (a *Application) RegisterService(svc *Service)
- func (a *Application) Setting(key string, value any, description string, validator OptionValueValidator)
- func (a *Application) WithAddons(addon ...*Addon)
- type Args
- type Assets
- type Command
- func (c *Command) AddFlag(f varflag.Flag)
- func (c *Command) AddSubCommand(cmd *Command)
- func (c *Command) AfterAlways(action func(s *Session) error)
- func (c *Command) AfterFailure(action func(s *Session, err error) error)
- func (c *Command) AfterSuccess(action func(s *Session) error)
- func (c *Command) Before(action ActionWithArgs)
- func (c *Command) Description() string
- func (c *Command) Do(action ActionWithArgs)
- func (c *Command) Err() error
- func (c *Command) Name() string
- func (c *Command) Usage() string
- type Cron
- type CronScheduler
- type Engine
- type Event
- type EventListener
- type Level
- type LogLevel
- type OptionArg
- type OptionKind
- type OptionValueValidator
- type Options
- type Service
- func (s *Service) Cron(setupFunc func(schedule CronScheduler))
- func (s *Service) OnAnyEvent(cb ActionWithEvent)
- func (s *Service) OnEvent(scope, key string, cb ActionWithEvent)
- func (s *Service) OnInitialize(action Action)
- func (s *Service) OnStart(action Action)
- func (s *Service) OnStop(action Action)
- func (s *Service) OnTick(action ActionTick)
- func (s *Service) OnTock(action ActionTock)
- type ServiceInfo
- type ServiceLoader
- type Session
- func (s *Session) API(addonName string) (API, error)
- func (s *Session) Config() *vars.Map
- func (s *Session) Deadline() (deadline time.Time, ok bool)
- func (s *Session) Destroy(err error)
- func (s *Session) Dispatch(ev Event)
- func (s *Session) Done() <-chan struct{}
- func (s *Session) Err() error
- func (s *Session) Get(key string) vars.Variable
- func (s *Session) Has(key string) bool
- func (s *Session) Log() *hlog.Logger
- func (s *Session) Ready() <-chan struct{}
- func (s *Session) RuntimeOpts() *vars.Map
- func (s *Session) ServiceInfo(svcurl string) (*ServiceInfo, error)
- func (s *Session) Set(key string, val any) error
- func (s *Session) Settings() *vars.Map
- func (s *Session) String() string
- func (s *Session) Value(key any) any
- func (s *Session) X() bool
- type TickerFuncs
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( ErrApplication = errors.New("application error") ErrCommand = errors.New("command error") ErrCommandFlags = errors.New("command flags error") ErrCommandAction = errors.New("command action error") ErrInvalidVersion = errors.New("invalid version") ErrEngine = errors.New("engine error") ErrSessionDestroyed = errors.New("session destroyed") ErrService = errors.New("service error") ErrHappy = errors.New("not so happy") ErrAddon = errors.New("addon error") )
Functions ¶
Types ¶
type ActionMigrate ¶ added in v0.2.0
type ActionTick ¶ added in v0.1.5
ActionTickFunc is operation set in given minimal time frame it can be executed. You can throttle tick/tocks to cap FPS or for [C|G]PU throttling.
Tock is helper called after each tick to separate logic processed in tick and do post processing on tick. Tocks are useful mostly for GPU ops which need to do post proccessing of frames rendered in tick.
type ActionTock ¶ added in v0.1.5
type ActionWithArgs ¶ added in v0.1.5
type ActionWithEvent ¶ added in v0.1.5
type ActionWithOptions ¶ added in v0.2.0
type Addon ¶
type Addon struct { API API // contains filtered or unexported fields }
func (*Addon) EmitsEvent ¶ added in v0.2.0
func (*Addon) OnRegister ¶ added in v0.2.0
func (addon *Addon) OnRegister(action ActionWithOptions)
func (*Addon) ProvidesCommand ¶ added in v0.2.0
func (*Addon) ProvidesService ¶ added in v0.2.0
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func New ¶ added in v0.1.5
func New(opts ...OptionArg) *Application
New returns new happy application instance. It panics if there is critical internal error or bug.
func (*Application) AddCommand ¶ added in v0.1.5
func (a *Application) AddCommand(cmd *Command)
func (*Application) AddFlag ¶ added in v0.1.5
func (a *Application) AddFlag(f varflag.Flag)
func (*Application) AfterAlways ¶ added in v0.1.5
func (a *Application) AfterAlways(action Action)
func (*Application) AfterFailure ¶ added in v0.1.5
func (a *Application) AfterFailure(action func(s *Session, err error) error)
func (*Application) AfterSuccess ¶ added in v0.1.5
func (a *Application) AfterSuccess(action Action)
func (*Application) Before ¶ added in v0.1.5
func (a *Application) Before(action ActionWithArgs)
func (*Application) Cron ¶ added in v0.1.5
func (a *Application) Cron(setup func(schedule CronScheduler))
func (*Application) Do ¶ added in v0.1.5
func (a *Application) Do(action ActionWithArgs)
func (*Application) Main ¶
func (a *Application) Main()
func (*Application) OnInstall ¶ added in v0.2.0
func (a *Application) OnInstall(action Action)
func (*Application) OnMigrate ¶ added in v0.2.0
func (a *Application) OnMigrate(ver string, up, down ActionMigrate)
func (*Application) OnTick ¶ added in v0.1.5
func (a *Application) OnTick(action ActionTick)
func (*Application) OnTock ¶ added in v0.1.5
func (a *Application) OnTock(action ActionTock)
func (*Application) RegisterService ¶
func (a *Application) RegisterService(svc *Service)
func (*Application) Setting ¶ added in v0.2.0
func (a *Application) Setting(key string, value any, description string, validator OptionValueValidator)
func (*Application) WithAddons ¶ added in v0.1.5
func (a *Application) WithAddons(addon ...*Addon)
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func NewCommand ¶ added in v0.1.5
func (*Command) AddSubCommand ¶ added in v0.1.5
func (*Command) AfterAlways ¶ added in v0.1.5
func (*Command) AfterFailure ¶ added in v0.1.5
func (*Command) AfterSuccess ¶ added in v0.1.5
func (*Command) Before ¶ added in v0.1.5
func (c *Command) Before(action ActionWithArgs)
func (*Command) Description ¶
func (*Command) Do ¶ added in v0.1.5
func (c *Command) Do(action ActionWithArgs)
type CronScheduler ¶
type Event ¶
func StartServicesEvent ¶ added in v0.1.5
func StopServicesEvent ¶ added in v0.1.5
type EventListener ¶
type EventListener interface { OnEvent(scope, key string, cb ActionWithEvent) OnAnyEvent(ActionWithEvent) }
type LogLevel ¶ added in v0.2.0
type LogLevel int
const ( // Happy Log Levels LogLevelSystemDebug LogLevel = LogLevel(slog.LevelDebug - 1) LogLevelDebug LogLevel = LogLevel(slog.LevelDebug) LogLevelInfo LogLevel = LogLevel(slog.LevelInfo) LogLevelTask LogLevel = LogLevel(slog.LevelInfo + 1) LogLevelOk LogLevel = LogLevel(slog.LevelInfo + 2) LogLevelNotice LogLevel = LogLevel(slog.LevelInfo + 3) LogLevelWarn LogLevel = LogLevel(slog.LevelWarn) LogLevelNotImplemented LogLevel = LogLevel(slog.LevelWarn + 1) LogLevelDeprecated LogLevel = LogLevel(slog.LevelWarn + 2) LogLevelIssue LogLevel = LogLevel(slog.LevelWarn + 3) LogLevelError LogLevel = LogLevel(slog.LevelError) LogLevelCritical LogLevel = LogLevel(slog.LevelError + 1) LogLevelAlert LogLevel = LogLevel(slog.LevelError + 2) LogLevelEmergency LogLevel = LogLevel(slog.LevelError + 3) LogLevelBUG LogLevel = 1000 LogLevelAlways LogLevel = math.MaxInt32 )
type OptionArg ¶ added in v0.2.0
type OptionArg struct {
// contains filtered or unexported fields
}
Option is used to define option and apply given key value to options.
type OptionKind ¶ added in v0.1.5
type OptionKind uint
const ( ReadOnlyOption OptionKind SettingsOption ConfigOption )
type OptionValueValidator ¶ added in v0.1.5
OptionValueValidator is callback function to validate given value, it recieves copy of value for validation. It MUST return error if validation fails, returned boolean indicates shoulkd that option be marked as radonly if validation succeeds.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options is general collection of settings attached to specific application component.
func NewOptions ¶ added in v0.1.5
NewOptions returns new named options with optiona validator when provided.
func (*Options) Accepts ¶ added in v0.1.5
Accepts reports whether given option key is accepted by Options.
type Service ¶
type Service struct { EventListener TickerFuncs // contains filtered or unexported fields }
func NewService ¶ added in v0.1.5
NewService cretes new draft service which you can compose before passing it to applciation or providing it from addon.
func (*Service) Cron ¶ added in v0.1.5
func (s *Service) Cron(setupFunc func(schedule CronScheduler))
Cron scheduled cron jobs to run when the service is running.
func (*Service) OnAnyEvent ¶ added in v0.1.5
func (s *Service) OnAnyEvent(cb ActionWithEvent)
OnAnyEvent called when any event is received.
func (*Service) OnEvent ¶ added in v0.1.5
func (s *Service) OnEvent(scope, key string, cb ActionWithEvent)
OnEvent is called when a specific event is received.
func (*Service) OnInitialize ¶
OnInitialize is called when app is preparing runtime and attaching services.
func (*Service) OnStart ¶
OnStart is called when service is requested to be started. For instace when command is requiring this service or whenever service is required on runtime via sess.RequireService call.
Start can be called multiple times in case of service restarts. If you do not want to allow service restarts you should implement your logic in OnStop when it's called first time and check that state OnStart.
func (*Service) OnTick ¶ added in v0.1.5
func (s *Service) OnTick(action ActionTick)
OnTick when set will be called every application tick when service is in running state.
func (*Service) OnTock ¶ added in v0.1.5
func (s *Service) OnTock(action ActionTock)
OnTock is called after every tick.
type ServiceInfo ¶ added in v0.1.5
type ServiceInfo struct {
// contains filtered or unexported fields
}
func (*ServiceInfo) Addr ¶ added in v0.1.5
func (s *ServiceInfo) Addr() *address.Address
func (*ServiceInfo) Failed ¶ added in v0.1.5
func (s *ServiceInfo) Failed() bool
func (*ServiceInfo) Name ¶ added in v0.1.5
func (s *ServiceInfo) Name() string
func (*ServiceInfo) Running ¶ added in v0.1.5
func (s *ServiceInfo) Running() bool
func (*ServiceInfo) StartedAt ¶ added in v0.1.5
func (s *ServiceInfo) StartedAt() time.Time
func (*ServiceInfo) StoppedAt ¶ added in v0.1.5
func (s *ServiceInfo) StoppedAt() time.Time
type ServiceLoader ¶
type ServiceLoader struct {
// contains filtered or unexported fields
}
func NewServiceLoader ¶ added in v0.1.5
func NewServiceLoader(sess *Session, svcs ...string) *ServiceLoader
func (*ServiceLoader) Err ¶
func (sl *ServiceLoader) Err() error
func (*ServiceLoader) Load ¶ added in v0.1.5
func (sl *ServiceLoader) Load() <-chan struct{}
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) Deadline ¶ added in v0.1.5
Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set. Successive calls to Deadline return the same results.
func (*Session) Done ¶ added in v0.1.5
func (s *Session) Done() <-chan struct{}
Done enables you to hook into chan to know when application exits however DO NOT use that for graceful shutdown actions. Use Application.AddExitFunc instead.
func (*Session) Err ¶ added in v0.1.5
Err returns session error if any or nil If Done is not yet closed, Err returns nil. If Done is closed, Err returns a non-nil error explaining why: Canceled if the context was canceled or DeadlineExceeded if the context's deadline passed. After Err returns a non-nil error, successive calls to Err return the same error.
func (*Session) Ready ¶
func (s *Session) Ready() <-chan struct{}
Ready returns channel which blocks until session considers application to be ready. It is ensured that Ready closes before root or command Do function is called.
func (*Session) RuntimeOpts ¶ added in v0.2.0
func (*Session) ServiceInfo ¶ added in v0.1.5
func (s *Session) ServiceInfo(svcurl string) (*ServiceInfo, error)
type TickerFuncs ¶
type TickerFuncs interface { // OnTick enables you to define func body for operation set // to call in minimal timeframe until session is valid and // service is running. OnTick(ActionTick) // OnTock is helper called right after OnTick to separate // your primary operations and post prossesing logic. OnTock(ActionTick) }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
pkg
|
|
address
Package address provides functions for working with "happy" addresses, which are URL-like strings that define the location of a resource in the "happy" system.
|
Package address provides functions for working with "happy" addresses, which are URL-like strings that define the location of a resource in the "happy" system. |
hlog
Package hlog is experimental logging packages which provides Custom handlerer for golang.org/x/exp/slog used within Happy.
|
Package hlog is experimental logging packages which provides Custom handlerer for golang.org/x/exp/slog used within Happy. |
hlog/internal/buffer
Package buffer provides a pool-allocated byte buffer.
|
Package buffer provides a pool-allocated byte buffer. |
varflag
Package varflag implements command-line flag parsing into compatible with package https://github.com/mkungla/happy/pkg/vars.
|
Package varflag implements command-line flag parsing into compatible with package https://github.com/mkungla/happy/pkg/vars. |
vars
Package vars provides the API to parse variables from various input formats/kinds to common key value pair.
|
Package vars provides the API to parse variables from various input formats/kinds to common key value pair. |
cli
Package cli provides utilities for happy command line interfaces.
|
Package cli provides utilities for happy command line interfaces. |
commands
Package commands provides commonly used commands which you can simply plug into your application.
|
Package commands provides commonly used commands which you can simply plug into your application. |
sarg
Package sarg is providing some common slog.Attr to use in your logging.
|
Package sarg is providing some common slog.Attr to use in your logging. |