Skip to content

Commit

Permalink
simplify RuntimeAddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed May 30, 2022
1 parent 5c7daa9 commit 151e72d
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions pkg/bass/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,19 @@ type RuntimeConfig struct {
}

// RuntimeAddrs contains addresses of various services.
type RuntimeAddrs struct {
addrs map[string]*url.URL
}

func (addrs *RuntimeAddrs) SetService(name string, u *url.URL) {
if addrs.addrs == nil {
addrs.addrs = map[string]*url.URL{}
}

addrs.addrs[name] = u
}
type RuntimeAddrs map[string]*url.URL

func (addrs RuntimeAddrs) Service(name string) (*url.URL, bool) {
if addrs.addrs == nil {
if addrs == nil {
return nil, false
}

u, found := addrs.addrs[name]
u, found := addrs[name]
return u, found
}

func (addrs *RuntimeAddrs) UnmarshalJSON(p []byte) error {
newAddrs := RuntimeAddrs{
addrs: make(map[string]*url.URL),
}
newAddrs := make(map[string]*url.URL)

var m map[string]string
if err := json.Unmarshal(p, &m); err != nil {
Expand All @@ -64,7 +52,7 @@ func (addrs *RuntimeAddrs) UnmarshalJSON(p []byte) error {
return fmt.Errorf("addr %q: %w", name, err)
}

newAddrs.addrs[name] = u
newAddrs[name] = u
}

*addrs = newAddrs
Expand Down

0 comments on commit 151e72d

Please sign in to comment.