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) Help(msg string)
- 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) Parents() []string
- func (c *Command) Usage() string
- type Cron
- type CronScheduler
- type Engine
- type Event
- type EventListener
- type LogLevel
- type LogLevelIface
- type Logger
- 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) AllowUserCancel()
- func (s *Session) Closed() <-chan struct{}
- 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() *logging.Logger
- func (s *Session) Opts() *vars.Map
- func (s *Session) Ready() <-chan struct{}
- 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
- 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 ¶
type ActionTick ¶
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 ActionWithArgs ¶
type ActionWithEvent ¶
type ActionWithOptions ¶
type Addon ¶
type Addon struct { API API // contains filtered or unexported fields }
func (*Addon) EmitsEvent ¶
func (*Addon) OnRegister ¶
func (addon *Addon) OnRegister(action ActionWithOptions)
func (*Addon) ProvidesCommand ¶
func (*Addon) ProvidesService ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...OptionArg) *Application
New returns new happy application instance. It panics if there is critical internal error or bug.
func NewWithLogger ¶
func NewWithLogger[L Logger[LVL], LVL LogLevelIface](logger L, level LVL, opts ...OptionArg) *Application
func (*Application) AddCommand ¶
func (a *Application) AddCommand(cmd *Command)
func (*Application) AddFlag ¶
func (a *Application) AddFlag(f varflag.Flag)
func (*Application) AfterAlways ¶
func (a *Application) AfterAlways(action Action)
func (*Application) AfterFailure ¶
func (a *Application) AfterFailure(action func(s *Session, err error) error)
func (*Application) AfterSuccess ¶
func (a *Application) AfterSuccess(action Action)
func (*Application) Before ¶
func (a *Application) Before(action ActionWithArgs)
func (*Application) Cron ¶
func (a *Application) Cron(setup func(schedule CronScheduler))
func (*Application) Do ¶
func (a *Application) Do(action ActionWithArgs)
func (*Application) Help ¶ added in v0.4.0
func (a *Application) Help(msg string)
func (*Application) Main ¶
func (a *Application) Main()
func (*Application) OnInstall ¶
func (a *Application) OnInstall(action Action)
func (*Application) OnMigrate ¶
func (a *Application) OnMigrate(ver string, up, down ActionMigrate)
func (*Application) OnTick ¶
func (a *Application) OnTick(action ActionTick)
func (*Application) OnTock ¶
func (a *Application) OnTock(action ActionTock)
func (*Application) RegisterService ¶
func (a *Application) RegisterService(svc *Service)
func (*Application) Setting ¶
func (a *Application) Setting(key string, value any, description string, validator OptionValueValidator)
func (*Application) WithAddons ¶
func (a *Application) WithAddons(addon ...*Addon)
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func NewCommand ¶
func (*Command) AddSubCommand ¶
func (*Command) AfterAlways ¶
func (*Command) AfterFailure ¶
func (*Command) AfterSuccess ¶
func (*Command) Before ¶
func (c *Command) Before(action ActionWithArgs)
func (*Command) Description ¶
func (*Command) Do ¶
func (c *Command) Do(action ActionWithArgs)
type CronScheduler ¶
type EventListener ¶
type EventListener interface { OnEvent(scope, key string, cb ActionWithEvent) OnAnyEvent(ActionWithEvent) }
type LogLevel ¶
type LogLevel int32
const ( LevelSystemDebug LogLevel = -10 // Level(slog.LevelDebug - 1) LevelDebug LogLevel = -4 // Level(slog.LevelDebug) LevelInfo LogLevel = 0 // Level(slog.LevelInfo) LevelTask LogLevel = 1 // Level(slog.LevelInfo + 1) LevelOk LogLevel = 2 // Level(slog.LevelInfo + 2) LevelNotice LogLevel = 3 // Level(slog.LevelInfo + 3) LevelWarn LogLevel = 4 // Level(slog.LevelWarn) LevelNotImplemented LogLevel = 5 // Level(slog.LevelWarn + 1) LevelDeprecated LogLevel = 6 // Level(slog.LevelWarn + 2) LevelIssue LogLevel = 7 // Level(slog.LevelWarn + 3) LevelError LogLevel = 8 // Level(slog.LevelError) LevelBUG LogLevel = math.MaxInt32 - 2 LevelAlways LogLevel = math.MaxInt32 - 1 LevelQuiet LogLevel = math.MaxInt32 )
type LogLevelIface ¶
type Logger ¶
type Logger[LVL LogLevelIface] interface { Level() LVL SetLevel(LVL) }
type OptionArg ¶
type OptionArg struct {
// contains filtered or unexported fields
}
Option is used to define option and apply given key value to options.
type OptionKind ¶
type OptionKind uint
const ( ReadOnlyOption OptionKind SettingsOption ConfigOption RuntimeOption )
type OptionValueValidator ¶
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 ¶
NewOptions returns new named options with optiona validator when provided.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
NewService cretes new draft service which you can compose before passing it to applciation or providing it from addon.
func (*Service) Cron ¶
func (s *Service) Cron(setupFunc func(schedule CronScheduler))
Cron scheduled cron jobs to run when the service is running.
func (*Service) OnAnyEvent ¶
func (s *Service) OnAnyEvent(cb ActionWithEvent)
OnAnyEvent called when any event is received.
func (*Service) OnEvent ¶
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 ¶
func (s *Service) OnTick(action ActionTick)
OnTick when set will be called every application tick when service is in running state.
func (*Service) OnTock ¶
func (s *Service) OnTock(action ActionTock)
OnTock is called after every tick.
type ServiceInfo ¶
type ServiceInfo struct {
// contains filtered or unexported fields
}
func (*ServiceInfo) Addr ¶
func (s *ServiceInfo) Addr() *address.Address
func (*ServiceInfo) Failed ¶
func (s *ServiceInfo) Failed() bool
func (*ServiceInfo) Name ¶
func (s *ServiceInfo) Name() string
func (*ServiceInfo) Running ¶
func (s *ServiceInfo) Running() bool
func (*ServiceInfo) StartedAt ¶
func (s *ServiceInfo) StartedAt() time.Time
func (*ServiceInfo) StoppedAt ¶
func (s *ServiceInfo) StoppedAt() time.Time
type ServiceLoader ¶
type ServiceLoader struct {
// contains filtered or unexported fields
}
func NewServiceLoader ¶
func NewServiceLoader(sess *Session, svcs ...string) *ServiceLoader
func (*ServiceLoader) Err ¶
func (sl *ServiceLoader) Err() error
func (*ServiceLoader) Load ¶
func (sl *ServiceLoader) Load() <-chan struct{}
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) AllowUserCancel ¶ added in v0.7.0
func (s *Session) AllowUserCancel()
AllowUserCancel allows user to cancel application by pressing Ctrl+C or sending SIGINT or SIGTERM while application is running. By default this is not allowed. If you want to allow user to cancel application, you call this method any point at application runtime. Calling this method multiple times has no effect and triggers Warning log message.
func (*Session) Closed ¶ added in v0.8.0
func (s *Session) Closed() <-chan struct{}
Closed returns channel which blocks until session is closed. It is ensured that Closed closes before root or command "Do" after functions are called. This is useful for graceful shutdown actions. e.g using together with AllowUserCancel
func (*Session) Config ¶
Config returns a map of all config options which are defined by application
func (*Session) Deadline ¶
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 ¶
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 or Cloesed instead.
func (*Session) Err ¶
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) Opts ¶ added in v0.6.0
Opts returns a map of all options which are defined by application turing current session life cycle.
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) ServiceInfo ¶
func (s *Session) ServiceInfo(svcurl string) (*ServiceInfo, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
addons
|
|
third-party/github
Module
|
|
cmd
|
|
hap
Module
|
|
examples
|
|
internal
|
|
cmd/hap
Module
|
|
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. |
branding
Module
|
|
cli/ansicolor
Module
|
|
devel/testutils
Module
|
|
options
Module
|
|
platform/daemon
Module
|
|
scheduling/cron
Module
|
|
settings
Module
|
|
strings/bexp
Module
|
|
strings/humanize
Module
|
|
strings/slug
Module
|
|
strings/textfmt
Module
|
|
vars
Module
|
|
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. |
logattr
Package logattr is providing some common slog.Attr to use in your logging.
|
Package logattr is providing some common slog.Attr to use in your logging. |
internal/cmd/hsdk
Module
|