NATS is an OCLIB tool

This commit is contained in:
mr 2024-08-21 10:21:17 +02:00
parent 649a1098c3
commit b7ecea25eb
2 changed files with 8 additions and 12 deletions

View File

@ -139,7 +139,7 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) { func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
var err error var err error
nats := tools.NATSCaller{} nats := tools.NewNATSCaller()
res, code, _ := wfa.LoadOne(id) res, code, _ := wfa.LoadOne(id)
if code != 200 { if code != 200 {
return 404, errors.New("could not load workflow") return 404, errors.New("could not load workflow")

View File

@ -31,21 +31,17 @@ func (d NATSMethod) String() string {
return [...]string{"remove", "create"}[d] return [...]string{"remove", "create"}[d]
} }
type NATSCaller struct { type natsCaller struct{}
natsUrl string
func NewNATSCaller() *natsCaller {
return &natsCaller{}
} }
func NewNATSCaller(url string) *NATSCaller { func (o *natsCaller) SetNATSPub(dataName string, method NATSMethod, data interface{}) string {
return &NATSCaller{ if GetConfig().NATSUrl == "" {
natsUrl: url,
}
}
func (o *NATSCaller) SetNATSPub(dataName string, method NATSMethod, data interface{}) string {
if o.natsUrl == "" {
return " -> NATS_SERVER is not set" return " -> NATS_SERVER is not set"
} }
nc, err := nats.Connect(o.natsUrl) nc, err := nats.Connect(GetConfig().NATSUrl)
if err != nil { if err != nil {
return " -> Could not reach NATS server : " + err.Error() return " -> Could not reach NATS server : " + err.Error()
} }