Skip to content

Commit

Permalink
fix(consul): don't parse address
Browse files Browse the repository at this point in the history
Using the DefaultConfig from consul and set the Address value, which Consul will then take care of
parsing
  • Loading branch information
mloberg committed Nov 16, 2022
1 parent 5e7f36a commit 45bd243
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
12 changes: 3 additions & 9 deletions consul.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"net/url"
"strings"

"github.com/hashicorp/consul/api"
Expand All @@ -14,15 +13,10 @@ type Consul struct {

// NewConsul returns a new instance of the Consul client using the given address
func NewConsul(addr string) (*Consul, error) {
a, err := url.Parse(addr)
if err != nil {
return nil, err
}
cfg := api.DefaultConfig()
cfg.Address = addr

c, err := api.NewClient(&api.Config{
Address: a.Host,
Scheme: a.Scheme,
})
c, err := api.NewClient(cfg)
if err != nil {
return nil, err
}
Expand Down
6 changes: 0 additions & 6 deletions consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestNewConsul(t *testing.T) {
c, err := NewConsul("foo:b\ar;baz")
assert.Nil(t, c)
assert.ErrorContains(t, err, "parse")
}

func TestConsulKey(t *testing.T) {
assert.Equal(t, consulKey("foo/bar/baz"), "BAZ")
assert.Equal(t, consulKey("test"), "TEST")
Expand Down

0 comments on commit 45bd243

Please sign in to comment.