Compare commits
No commits in common. "main" and "0.0.3" have entirely different histories.
3 changed files with 2 additions and 58 deletions
|
|
@ -1,11 +0,0 @@
|
|||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Variable struct {
|
||||
Name string `json:"name"`
|
||||
VarType string `json:"type,omitempty"`
|
||||
Value any `json:"value,omitempty"`
|
||||
Created *time.Time `json:"created,omitempty"`
|
||||
Updated *time.Time `json:"updated,omitempty"`
|
||||
}
|
||||
47
plugis.go
47
plugis.go
|
|
@ -4,16 +4,14 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/nats-io/nats.go/micro"
|
||||
nats_service "github.com/telemac/plugisservice/pkg/nats-service"
|
||||
"iter"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/micro"
|
||||
"github.com/telemac/plugisservice/model"
|
||||
nats_service "github.com/telemac/plugisservice/pkg/nats-service"
|
||||
|
||||
"github.com/telemac/goutils/net"
|
||||
"github.com/telemac/goutils/task"
|
||||
|
||||
|
|
@ -37,11 +35,6 @@ var (
|
|||
ErrNatsConnectionNil = errors.New("nats connection is nil")
|
||||
)
|
||||
|
||||
type Event[T any] struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Data T `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// SetLogger sets the logger for the Plugis instance.
|
||||
func (plugis *Plugis) SetLogger(log *slog.Logger) {
|
||||
plugis.logger = log
|
||||
|
|
@ -252,39 +245,3 @@ func (plugis *Plugis) StartService(svc PlugisServiceIntf) (*nats_service.NatsSer
|
|||
})
|
||||
return service, err
|
||||
}
|
||||
|
||||
// VariableSet sets a variable with the given name, value, and type, then publishes it to a corresponding topic.
|
||||
func (plugis *Plugis) VariableSet(name string, value any, varType string) error {
|
||||
variable := model.Variable{
|
||||
Name: name,
|
||||
Value: value,
|
||||
VarType: varType,
|
||||
}
|
||||
event := Event[model.Variable]{
|
||||
Type: "variable.set",
|
||||
Data: variable,
|
||||
}
|
||||
topic := "variable.set." + name
|
||||
payload, err := json.Marshal(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return plugis.Publish(topic, payload)
|
||||
}
|
||||
|
||||
// VariableUnset unsets a variable with the given name, then publishes it to a corresponding topic.
|
||||
func (plugis *Plugis) VariableUnset(name string) error {
|
||||
variable := model.Variable{
|
||||
Name: name,
|
||||
}
|
||||
event := Event[model.Variable]{
|
||||
Type: "variable.unset",
|
||||
Data: variable,
|
||||
}
|
||||
topic := "variable.unset." + name
|
||||
payload, err := json.Marshal(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return plugis.Publish(topic, payload)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ type PlugisIntf interface {
|
|||
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
|
||||
}
|
||||
|
||||
// ServiceInfo is the information about a service.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue