Documentation
¶
Index ¶
- Variables
- type Endpoint
- type Event
- type Metadata
- type Plugis
- func (plugis *Plugis) GetServices(ctx context.Context) ([]ServiceInfo, error)
- func (plugis *Plugis) Logger() *slog.Logger
- func (plugis *Plugis) Nats() *nats.Conn
- func (plugis *Plugis) Prefix() string
- func (plugis *Plugis) Publish(topic string, payload []byte) error
- func (plugis *Plugis) Request(subj string, data []byte, timeout time.Duration) (*nats.Msg, error)
- func (plugis *Plugis) RequestCtx(ctx context.Context, subj string, data []byte) (*nats.Msg, error)
- func (plugis *Plugis) RequestMany(ctx context.Context, subject string, data []byte, ...) (iter.Seq2[*nats.Msg, error], error)
- func (plugis *Plugis) SetLogger(log *slog.Logger)
- func (plugis *Plugis) SetNats(nc *nats.Conn)
- func (plugis *Plugis) SetPrefix(prefix string)
- func (plugis *Plugis) StartService(svc PlugisServiceIntf) (*nats_service.NatsService, error)
- func (plugis *Plugis) VariableSet(name string, value any, varType string) error
- func (plugis *Plugis) VariableUnset(name string) error
- type PlugisIntf
- type PlugisServiceIntf
- type ServiceInfo
- type ServiceMetadata
- type ServiceRunner
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNatsNotConnected = errors.New("nats not connected") ErrNatsConnectionNil = errors.New("nats connection is nil") )
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint struct {
Name string `json:"name"`
Subject string `json:"subject"`
QueueGroup string `json:"queue_group"`
Metadata Metadata `json:"metadata,omitempty"`
}
Endpoint is the information about an endpoint.
type Metadata ¶
Metadata is a map of key-value pairs that can be used to store additional information about a service/endpoint
type Plugis ¶
type Plugis struct {
// contains filtered or unexported fields
}
Plugis is the default implementation of the PlugisIntf that provides the functionality to plugis services.
func (*Plugis) GetServices ¶
func (plugis *Plugis) GetServices(ctx context.Context) ([]ServiceInfo, error)
GetServices sends a request to the $SRV.INFO subject and returns a list of services.
func (*Plugis) RequestCtx ¶
RequestCtx sends a request to the nats connection and returns a single message. context is used for timeout and cancellation.
func (*Plugis) RequestMany ¶
func (plugis *Plugis) RequestMany(ctx context.Context, subject string, data []byte, opts ...natsext.RequestManyOpt) (iter.Seq2[*nats.Msg, error], error)
RequestMany sends a request to the nats connection and returns a sequence of messages.
func (*Plugis) StartService ¶
func (plugis *Plugis) StartService(svc PlugisServiceIntf) (*nats_service.NatsService, error)
StartService initializes and starts a NATS service for the given PlugisServiceIntf implementation. It returns the created NatsService and any error encountered during the creation process.
func (*Plugis) VariableSet ¶
VariableSet sets a variable with the given name, value, and type, then publishes it to a corresponding topic.
func (*Plugis) VariableUnset ¶
VariableUnset unsets a variable with the given name, then publishes it to a corresponding topic.
type PlugisIntf ¶
type PlugisIntf interface {
SetLogger(*slog.Logger)
Logger() *slog.Logger
SetNats(*nats.Conn)
Nats() *nats.Conn
SetPrefix(prefix string)
Prefix() string
Publish(topic string, payload []byte) error
Request(subj string, data []byte, timeout time.Duration) (*nats.Msg, error)
RequestMany(ctx context.Context, subject string, data []byte, opts ...natsext.RequestManyOpt) (iter.Seq2[*nats.Msg, error], error)
GetServices(ctx context.Context) ([]ServiceInfo, error)
StartService(svc PlugisServiceIntf) (*nats_service.NatsService, error)
VariableSet(name string, value any, varType string) error
VariableUnset(name string) error
}
PlugisIntf holds the methods that can be used by a plugis service.
type PlugisServiceIntf ¶
type PlugisServiceIntf interface {
Run(ctx context.Context) error
Name() string
Description() string
Version() string
Metadata() Metadata
PlugisIntf
}
PlugisServiceIntf is the interface that must be implemented by all plugis services.
type ServiceInfo ¶
type ServiceInfo struct {
Name string `json:"name"`
Id string `json:"id"`
Description string `json:"description"`
Version string `json:"version"`
Type string `json:"type"`
Metadata Metadata `json:"metadata"` // contains at least ServiceMetadata fields
Endpoints []Endpoint `json:"endpoints"`
}
ServiceInfo is the information about a service.
type ServiceMetadata ¶
type ServiceMetadata struct {
Hostname string `json:"hostname"`
MAC string `json:"mac"`
Platform string `json:"platform"`
Prefix string `json:"prefix"`
StartedAt string `json:"started_at"`
}
ServiceMetadata is the metadata about a service.
func NewServiceMetadata ¶
func NewServiceMetadata(prefix string, startedAt time.Time) (*ServiceMetadata, error)
NewServiceMetadata creates and fills a ServiceMetadata structure
func (*ServiceMetadata) Meta ¶
func (smd *ServiceMetadata) Meta() Metadata
Meta returns ServiceMetaData as map[string]string
type ServiceRunner ¶
type ServiceRunner struct {
// contains filtered or unexported fields
}
ServiceRunner is a struct that runs one or more services.
func NewServiceRunner ¶
func (*ServiceRunner) Start ¶
func (sr *ServiceRunner) Start(ctx context.Context, svc PlugisServiceIntf)
Start starts a service.