Skip to content

Commit 4051881

Browse files
committed
move nats config back to the messaging package
1 parent 1d502ec commit 4051881

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
9999
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
100100
github.com/nats-io/stan.go v0.4.5 h1:lPZ9y1jVGiXcTaUc1SnEIWPYfh0avuEiHBePNJYgpPk=
101101
github.com/nats-io/stan.go v0.4.5/go.mod h1:Ji7mK6gRZJSH1nc3ZJH6vi7zn/QnZhpR9Arm4iuzsUQ=
102+
github.com/nats-io/stan.go v0.5.0 h1:ZaSPMb6jnDXsSlOACynJrUiB3Evleg3ZyyX+rnf3TlQ=
102103
github.com/nats-io/stan.go v0.5.0/go.mod h1:dYqB+vMN3C2F9pT1FRQpg9eHbjPj6mP0yYuyBNuXHZE=
103104
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
104105
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=

nconf/nats.go renamed to messaging/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package nconf
1+
package messaging
22

33
import (
44
"fmt"
55
"strings"
66
"time"
77

8+
"github.com/netlify/netlify-commons/nconf"
9+
810
"github.com/pkg/errors"
911

1012
"github.com/nats-io/stan.go"
@@ -28,10 +30,10 @@ type NatsAuth struct {
2830
}
2931

3032
type NatsConfig struct {
31-
TLS *TLSConfig `mapstructure:"tls_conf"`
32-
DiscoveryName string `mapstructure:"discovery_name" split_words:"true"`
33-
Servers []string `mapstructure:"servers"`
34-
Auth NatsAuth `mapstructure:"auth"`
33+
TLS *nconf.TLSConfig `mapstructure:"tls_conf"`
34+
DiscoveryName string `mapstructure:"discovery_name" split_words:"true"`
35+
Servers []string `mapstructure:"servers"`
36+
Auth NatsAuth `mapstructure:"auth"`
3537

3638
// for streaming
3739
ClusterID string `mapstructure:"cluster_id" split_words:"true"`

messaging/nats.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/nats-io/nats.go"
1111
"github.com/nats-io/stan.go"
12-
"github.com/netlify/netlify-commons/nconf"
1312
"github.com/pkg/errors"
1413
"github.com/sirupsen/logrus"
1514
)
@@ -22,7 +21,7 @@ func init() {
2221
silent = logrus.NewEntry(l)
2322
}
2423

25-
func ConfigureNatsConnection(config *nconf.NatsConfig, log logrus.FieldLogger) (*nats.Conn, error) {
24+
func ConfigureNatsConnection(config *NatsConfig, log logrus.FieldLogger) (*nats.Conn, error) {
2625
if log == nil {
2726
log = silent
2827
}
@@ -49,7 +48,7 @@ func ConfigureNatsConnection(config *nconf.NatsConfig, log logrus.FieldLogger) (
4948
return nc, nil
5049
}
5150

52-
func ConnectToNats(config *nconf.NatsConfig, opts ...nats.Option) (*nats.Conn, error) {
51+
func ConnectToNats(config *NatsConfig, opts ...nats.Option) (*nats.Conn, error) {
5352
tlsConfig, err := config.TLS.TLSConfig()
5453
if err != nil {
5554
return nil, errors.Wrap(err, "Failed to configure TLS")
@@ -61,11 +60,11 @@ func ConnectToNats(config *nconf.NatsConfig, opts ...nats.Option) (*nats.Conn, e
6160
}
6261

6362
switch strings.ToLower(config.Auth.Method) {
64-
case nconf.NatsAuthMethodUser:
63+
case NatsAuthMethodUser:
6564
opts = append(opts, nats.UserInfo(config.Auth.User, config.Auth.Password))
66-
case nconf.NatsAuthMethodToken:
65+
case NatsAuthMethodToken:
6766
opts = append(opts, nats.Token(config.Auth.Token))
68-
case nconf.NatsAuthMethodTLS:
67+
case NatsAuthMethodTLS:
6968
// if using TLS auth, make sure the client certificate is loaded
7069
if tlsConfig == nil || len(tlsConfig.Certificates) == 0 {
7170
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
7877
return nats.Connect(config.ServerString(), opts...)
7978
}
8079

81-
func ConfigureNatsStreaming(config *nconf.NatsConfig, log logrus.FieldLogger) (stan.Conn, error) {
80+
func ConfigureNatsStreaming(config *NatsConfig, log logrus.FieldLogger) (stan.Conn, error) {
8281
// connect to the underlying instance
8382
nc, err := ConfigureNatsConnection(config, log)
8483
if err != nil {
@@ -93,7 +92,7 @@ func ConfigureNatsStreaming(config *nconf.NatsConfig, log logrus.FieldLogger) (s
9392
return conn, nil
9493
}
9594

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) {
9796
if config.ClusterID == "" {
9897
return nil, errors.New("Must provide a cluster ID to connect to streaming nats")
9998
}

0 commit comments

Comments
 (0)