9
9
10
10
"github.com/nats-io/nats.go"
11
11
"github.com/nats-io/stan.go"
12
- "github.com/netlify/netlify-commons/nconf"
13
12
"github.com/pkg/errors"
14
13
"github.com/sirupsen/logrus"
15
14
)
@@ -22,7 +21,7 @@ func init() {
22
21
silent = logrus .NewEntry (l )
23
22
}
24
23
25
- func ConfigureNatsConnection (config * nconf. NatsConfig , log logrus.FieldLogger ) (* nats.Conn , error ) {
24
+ func ConfigureNatsConnection (config * NatsConfig , log logrus.FieldLogger ) (* nats.Conn , error ) {
26
25
if log == nil {
27
26
log = silent
28
27
}
@@ -49,7 +48,7 @@ func ConfigureNatsConnection(config *nconf.NatsConfig, log logrus.FieldLogger) (
49
48
return nc , nil
50
49
}
51
50
52
- func ConnectToNats (config * nconf. NatsConfig , opts ... nats.Option ) (* nats.Conn , error ) {
51
+ func ConnectToNats (config * NatsConfig , opts ... nats.Option ) (* nats.Conn , error ) {
53
52
tlsConfig , err := config .TLS .TLSConfig ()
54
53
if err != nil {
55
54
return nil , errors .Wrap (err , "Failed to configure TLS" )
@@ -61,11 +60,11 @@ func ConnectToNats(config *nconf.NatsConfig, opts ...nats.Option) (*nats.Conn, e
61
60
}
62
61
63
62
switch strings .ToLower (config .Auth .Method ) {
64
- case nconf . NatsAuthMethodUser :
63
+ case NatsAuthMethodUser :
65
64
opts = append (opts , nats .UserInfo (config .Auth .User , config .Auth .Password ))
66
- case nconf . NatsAuthMethodToken :
65
+ case NatsAuthMethodToken :
67
66
opts = append (opts , nats .Token (config .Auth .Token ))
68
- case nconf . NatsAuthMethodTLS :
67
+ case NatsAuthMethodTLS :
69
68
// if using TLS auth, make sure the client certificate is loaded
70
69
if tlsConfig == nil || len (tlsConfig .Certificates ) == 0 {
71
70
return nil , fmt .Errorf ("TLS auth method is configured but no certificate was loaded" )
@@ -78,7 +77,7 @@ func ConnectToNats(config *nconf.NatsConfig, opts ...nats.Option) (*nats.Conn, e
78
77
return nats .Connect (config .ServerString (), opts ... )
79
78
}
80
79
81
- func ConfigureNatsStreaming (config * nconf. NatsConfig , log logrus.FieldLogger ) (stan.Conn , error ) {
80
+ func ConfigureNatsStreaming (config * NatsConfig , log logrus.FieldLogger ) (stan.Conn , error ) {
82
81
// connect to the underlying instance
83
82
nc , err := ConfigureNatsConnection (config , log )
84
83
if err != nil {
@@ -93,7 +92,7 @@ func ConfigureNatsStreaming(config *nconf.NatsConfig, log logrus.FieldLogger) (s
93
92
return conn , nil
94
93
}
95
94
96
- func ConnectToNatsStreaming (nc * nats.Conn , config * nconf. NatsConfig , log logrus.FieldLogger ) (stan.Conn , error ) {
95
+ func ConnectToNatsStreaming (nc * nats.Conn , config * NatsConfig , log logrus.FieldLogger ) (stan.Conn , error ) {
97
96
if config .ClusterID == "" {
98
97
return nil , errors .New ("Must provide a cluster ID to connect to streaming nats" )
99
98
}
0 commit comments