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)
- func LoadServices(sess *Session, svcs ...string)
- func Option(key string, val any) options.Arg
- type API
- type Action
- type ActionTick
- type ActionTock
- type ActionWithArgs
- type ActionWithEvent
- type ActionWithOptions
- type ActionWithPrevErr
- type Addon
- func (addon *Addon) Emits(scope, key, description string, example *vars.Map)
- func (addon *Addon) EmitsEvent(event Event)
- func (addon *Addon) OnRegister(action Action)
- func (addon *Addon) ProvidesAPI(api API)
- func (addon *Addon) ProvidesCommand(cmd *Command)
- func (addon *Addon) ProvidesService(svc *Service)
- type AddonInfo
- type Args
- type Brand
- type BrandFunc
- type Command
- func (c *Command) AddFlag(fn varflag.FlagCreateFunc) *Command
- func (c *Command) AddInfo(paragraph string) *Command
- func (c *Command) AddSubCommand(cmd *Command) *Command
- func (c *Command) AfterAlways(a ActionWithPrevErr) *Command
- func (c *Command) AfterFailure(a ActionWithPrevErr) *Command
- func (c *Command) AfterSuccess(a Action) *Command
- func (c *Command) Before(a ActionWithArgs) *Command
- func (c *Command) DescribeCategory(cat, desc string) *Command
- func (c *Command) Do(action ActionWithArgs) *Command
- func (c *Command) WithFlags(flagfuncs ...varflag.FlagCreateFunc) *Command
- type Cron
- type CronScheduler
- type Event
- type EventListener
- type Flags
- type Main
- func (m *Main) AddInfo(paragraph string) *Main
- func (m *Main) AfterAlways(a ActionWithPrevErr) *Main
- func (m *Main) AfterFailure(a ActionWithPrevErr) *Main
- func (m *Main) AfterSuccess(a Action) *Main
- func (m *Main) Before(a ActionWithArgs) *Main
- func (m *Main) BeforeAlways(a ActionWithArgs) *Main
- func (m *Main) Do(a ActionWithArgs) *Main
- func (m *Main) Run()
- func (m *Main) SetOptions(a ...options.Arg) *Main
- func (m *Main) Tick(a ActionTick) *Main
- func (m *Main) Tock(a ActionTock) *Main
- func (m *Main) WithAddon(addon *Addon) *Main
- func (m *Main) WithBrand(b BrandFunc) *Main
- func (m *Main) WithCommand(cmd *Command) *Main
- func (m *Main) WithFlag(flag varflag.FlagCreateFunc) *Main
- func (m *Main) WithLogger(l logging.Logger) *Main
- func (m *Main) WithMigrations(mm *migration.Manager) *Main
- func (m *Main) WithOptions(opts ...options.OptionSpec) *Main
- func (m *Main) WithService(svc *Service) *Main
- 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) OnRegister(action Action)
- func (s *Service) OnStart(action Action)
- func (s *Service) OnStop(action Action)
- func (s *Service) Tick(action ActionTick)
- func (s *Service) Tock(action ActionTock)
- type ServiceInfo
- type ServiceLoader
- type Session
- func (s *Session) API(addonName string) (API, error)
- func (s *Session) AllowUserCancel()
- func (s *Session) Deadline() (deadline time.Time, ok bool)
- func (s *Session) Describe(key string) string
- 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() *options.Options
- func (s *Session) Ready() <-chan struct{}
- func (s *Session) ServiceInfo(svcurl string) (*ServiceInfo, error)
- func (s *Session) ServiceLoader(svcs ...string) *ServiceLoader
- func (s *Session) Set(key string, val any) error
- func (s *Session) Settings() *settings.Profile
- func (s *Session) Stats() stats.State
- func (s *Session) String() string
- func (s *Session) Value(key any) any
- type Settings
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrCommand = errors.New("command error") ErrCommandFlags = errors.New("command flags error") ErrCommandHasNoParent = errors.New("command has no parent command") )
var ( ErrSession = fmt.Errorf("%w:session", Error) ErrSessionDestroyed = fmt.Errorf("%w:destroyed", ErrSession) )
var ErrAddon = fmt.Errorf("%w:addon", Error)
var ErrEngine = fmt.Errorf("%w:engine", Error)
var (
ErrService = fmt.Errorf("%s:svc", Error)
)
var (
Error = errors.New("happy")
)
Functions ¶
func LoadServices ¶ added in v0.22.0
LoadServices is a non blocking helper function to load services in backgrond
Types ¶
type ActionWithArgs ¶
type ActionWithFlags func(sess *Session, flags Flags) error
type ActionWithEvent ¶
type ActionWithPrevErr ¶ added in v0.12.0
type Addon ¶
type Addon struct {
// contains filtered or unexported fields
}
func (*Addon) EmitsEvent ¶
func (*Addon) OnRegister ¶
func (*Addon) ProvidesAPI ¶ added in v0.12.0
func (*Addon) ProvidesCommand ¶
func (*Addon) ProvidesService ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func (*Command) AddSubCommand ¶
func (*Command) AfterAlways ¶
func (c *Command) AfterAlways(a ActionWithPrevErr) *Command
func (*Command) AfterFailure ¶
func (c *Command) AfterFailure(a ActionWithPrevErr) *Command
func (*Command) AfterSuccess ¶
func (*Command) Before ¶
func (c *Command) Before(a ActionWithArgs) *Command
func (*Command) DescribeCategory ¶ added in v0.20.0
func (*Command) Do ¶
func (c *Command) Do(action ActionWithArgs) *Command
type CronScheduler ¶
type EventListener ¶
type EventListener interface { OnEvent(scope, key string, cb ActionWithEvent) OnAnyEvent(ActionWithEvent) }
type Main ¶ added in v0.12.0
type Main struct {
// contains filtered or unexported fields
}
func New ¶
New is alias to prototype.New
Example ¶
package main import ( "fmt" "github.com/happy-sdk/happy" "github.com/happy-sdk/happy/sdk/logging" ) func main() { log := logging.NewTestLogger(logging.LevelError) app := happy.New(happy.Settings{}) app.WithLogger(log) app.Do(func(sess *happy.Session, args happy.Args) error { sess.Log().Println("Hello, world!") return nil }) app.Run() fmt.Println(log.Output()) }
Output: {"level":"out","msg":"Hello, world!"}
func (*Main) AfterAlways ¶ added in v0.12.0
func (m *Main) AfterAlways(a ActionWithPrevErr) *Main
AfterAlways is executed after every application execution.
func (*Main) AfterFailure ¶ added in v0.12.0
func (m *Main) AfterFailure(a ActionWithPrevErr) *Main
AfterFailure is executed after every failed application execution.
func (*Main) AfterSuccess ¶ added in v0.12.0
AfterSuccess is executed after every successful application execution.
func (*Main) Before ¶ added in v0.12.0
func (m *Main) Before(a ActionWithArgs) *Main
Before is executed only when no command is specified.
func (*Main) BeforeAlways ¶ added in v0.12.0
func (m *Main) BeforeAlways(a ActionWithArgs) *Main
BeforeAlways is executed before any command.
func (*Main) Do ¶ added in v0.12.0
func (m *Main) Do(a ActionWithArgs) *Main
Do is executed only when no command is specified.
func (*Main) Tick ¶ added in v0.12.0
func (m *Main) Tick(a ActionTick) *Main
Tick when set is executed on every tick defined by Settings.ThrottleTicks interval.
func (*Main) Tock ¶ added in v0.12.0
func (m *Main) Tock(a ActionTock) *Main
Tock when set is executed right after Tick. If Tick returns error then Tock is not executed.
func (*Main) WithCommand ¶ added in v0.12.0
WithCommand adds command to the application.
func (*Main) WithFlag ¶ added in v0.12.0
func (m *Main) WithFlag(flag varflag.FlagCreateFunc) *Main
WithFlag adds flag to the application.
func (*Main) WithLogger ¶ added in v0.12.0
WithLogger sets application logger.
func (*Main) WithMigrations ¶ added in v0.12.0
WithMigrations adds migrations manager to the application.
func (*Main) WithOptions ¶ added in v0.12.0
func (m *Main) WithOptions(opts ...options.OptionSpec) *Main
func (*Main) WithService ¶ added in v0.12.0
WithService adds service to the application.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(name string, opts ...options.OptionSpec) *Service
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) OnRegister ¶ added in v0.19.0
OnRegister is called when app is preparing runtime and attaching services, This does not mean that service will be used or started.
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) Tick ¶ added in v0.12.0
func (s *Service) Tick(action ActionTick)
OnTick when set will be called every application tick when service is in running state.
func (*Service) Tock ¶ added in v0.12.0
func (s *Service) Tock(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
NewServiceLoader creates new service loader which can be used to load services before application starts or during runtime.
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 unless application is blocked with Wait.
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)
func (*Session) ServiceLoader ¶ added in v0.12.0
func (s *Session) ServiceLoader(svcs ...string) *ServiceLoader
ServiceLoader calls NewServiceLoader with current session as first argument.
type Settings ¶ added in v0.11.0
type Settings struct { Name settings.String `key:"app.name" default:"Happy Prototype"` Slug settings.String `key:"app.slug" default:""` Description settings.String `key:"app.description" default:""` CopyrightBy settings.String `key:"app.copyright.by"` CopyrightSince settings.Uint `key:"app.copyright.since" default:"0" mutation:"once"` License settings.String `key:"app.license"` MainArgcMax settings.Uint `key:"app.main.argn_max" default:"0"` TimeLocation settings.String `key:"app.datetime.location,save" default:"Local" mutation:"mutable"` EngineThrottleTicks settings.Duration `key:"app.engine.throttle_ticks,save" default:"1s" mutation:"once"` ServiceLoaderTimeout settings.Duration `key:"app.service_loader.timeout" default:"30s" mutation:"once"` Instance instance.Settings `key:"app.instance"` StatsEnabled settings.Bool `key:"app.stats.enabled" default:"false" mutation:"once"` // contains filtered or unexported fields }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
addons
|
|
third-party/github
Module
|
|
cmd
|
|
hap
Module
|
|
cmd/hap
Module
|
|
pkg
|
|
branding
Module
|
|
cli/ansicolor
Module
|
|
devel/testutils
Module
|
|
platform/daemon
Module
|
|
scheduling/cron
Module
|
|
settings
Module
|
|
strings/bexp
Module
|
|
strings/humanize
Module
|
|
strings/textfmt
Module
|
|
vars
Module
|
|
version
Module
|
|
cli
Package cli provides utilities for happy command line interfaces.
|
Package cli provides utilities for happy command line interfaces. |
networking/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. |
options
Package oprions provides a way to define and manage options for application components.
|
Package oprions provides a way to define and manage options for application components. |