Documentation
¶
Index ¶
- Variables
- func ResolveAddress(sess *session.Context, s string) (string, error)
- type Container
- func (c *Container) CanRetry() bool
- func (c *Container) Cancel(err error)
- func (c *Container) Done() <-chan struct{}
- func (c *Container) HandleEvent(sess *session.Context, ev events.Event)
- func (c *Container) HasTick() bool
- func (c *Container) Info() *service.Info
- func (c *Container) Listeners() []string
- func (c *Container) Register(sess *session.Context) error
- func (c *Container) Retries() int
- func (c *Container) Settings() service.Config
- func (c *Container) Start(ectx context.Context, sess *session.Context) (err error)
- func (c *Container) Stop(sess *session.Context, e error) (err error)
- func (c *Container) Tick(sess *session.Context, ts time.Time, delta time.Duration) error
- func (c *Container) Tock(sess *session.Context, delta time.Duration, tps int) error
- type CronScheduler
- type Info
- type Service
- func (s *Service) Cron(setupFunc func(schedule CronScheduler))
- func (s *Service) Name() string
- func (s *Service) OnAnyEvent(cb events.ActionWithEvent[*session.Context])
- func (s *Service) OnEvent(scope, key string, cb events.ActionWithEvent[*session.Context])
- func (s *Service) OnRegister(action action.Action)
- func (s *Service) OnStart(action action.Action)
- func (s *Service) OnStop(action action.WithPrevErr)
- func (s *Service) Slug() string
- func (s *Service) StartEvent() events.Event
- func (s *Service) StopEvent() events.Event
- func (s *Service) Tick(action action.Tick)
- func (s *Service) Tock(action action.Tock)
- type ServiceLoader
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ResolveAddress ¶ added in v0.30.0
ResolveAddress resolves the given service name or address `s` into a full service address based on the current application’s configuration.
It retrieves the base application address from the session context (`app.address`) and attempts to resolve `s` into a complete service address.
Example:
addr, err := ResolveAddress(sess, "serviceA")
if err != nil {
log.Fatal("Failed to resolve service address:", err)
}
fmt.Println("Resolved address:", addr)
Returns the resolved service address as a string or an error if resolution fails.
Types ¶
type Container ¶ added in v0.25.0
type Container struct {
// contains filtered or unexported fields
}
func NewContainer ¶ added in v0.25.0
func (*Container) HandleEvent ¶ added in v0.25.0
type CronScheduler ¶ added in v0.25.0
type Service ¶ added in v0.25.0
type Service struct {
// contains filtered or unexported fields
}
func New ¶ added in v0.25.0
New cretes new draft service which you can compose before passing it to applciation or providing it from addon.
func (*Service) Cron ¶ added in v0.25.0
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.25.0
func (s *Service) OnAnyEvent(cb events.ActionWithEvent[*session.Context])
OnAnyEvent called when any event is received.
func (*Service) OnRegister ¶ added in v0.25.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 ¶ added in v0.25.0
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) OnStop ¶ added in v0.25.0
func (s *Service) OnStop(action action.WithPrevErr)
OnStop is called when runtime request to stop the service is recieved.
func (*Service) StartEvent ¶ added in v0.36.0
StartEvent returns the event to start the service.
type ServiceLoader ¶ added in v0.25.0
type ServiceLoader struct {
// contains filtered or unexported fields
}
func NewLoader ¶ added in v0.25.0
func NewLoader(sess *session.Context, svcs ...string) *ServiceLoader
NewLoader creates a new ServiceLoader instance that initializes and prepares services for loading.
It accepts a session context and an optional list of service addresses. The loader will attempt to resolve and store service addresses based on the provided session configuration.
Example usage:
loader := NewLoader(sess, "serviceA", "serviceB")
<-loader.Load()
if err := loader.Err(); err != nil {
log.Fatal("Service loading failed:", err)
}
Returns a pointer to a ServiceLoader instance.
func (*ServiceLoader) Err ¶ added in v0.25.0
func (sl *ServiceLoader) Err() error
Err returns an aggregated error if any occurred during the service loading process.
It should be called **after** the Load() channel unlocks to check whether loading was successful.
Example:
loader := NewLoader(sess, "serviceA")
<-loader.Load()
if err := loader.Err(); err != nil {
log.Fatal("Failed to load services:", err)
}
Returns an error or nil if no errors occurred.
func (*ServiceLoader) Load ¶ added in v0.25.0
func (sl *ServiceLoader) Load() <-chan struct{}
Load starts the service loading process and returns a channel that signals when the loading is complete.
This function ensures that all requested services are either started or their failure is logged. If services fail to start within a configured timeout, Load will cancel the process and return an error via Err().
Example:
loader := NewLoader(sess, "serviceA", "serviceB")
<-loader.Load()
if err := loader.Err(); err != nil {
log.Fatal("Service loading failed:", err)
}
Returns a receive-only channel that signals completion when closed.