ircd/nats.go

31 lines
618 B
Go

// vim:ts=4:sts=4:sw=4:noet:tw=72
package ircd
import (
"strings"
"github.com/nats-io/nats"
)
type NatsConnector struct {
natsConn *nats.Conn
subscriptions map[string]*nats.Subscription
}
func NewNatsConnector(servers *string) *NatsConnector {
opts := nats.DefaultOptions
opts.Servers = strings.Split(*servers, ",")
for i, s := range opts.Servers {
opts.Servers[i] = strings.Trim(s, " ")
}
//opts.Secure = *ssl
opts.Secure = false
conn, err := opts.Connect()
if err != nil {
// foo
}
subs := make(map[string]*nats.Subscription)
return &NatsConnector{natsConn: conn, subscriptions: subs}
}