Skip to content

Commit d66fbbc

Browse files
committed
Some more overdue go fmt.
1 parent 77da55c commit d66fbbc

22 files changed

+228
-229
lines changed

addresses_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func Test_Addresses(t *testing.T) {
4444
// See caveat for findPrivateAddresses() above
4545
Convey("Returns an address", func() {
4646
addresses, _ := findPrivateAddresses()
47-
result, err := getPublishedIP([]string{}, nil)
47+
result, err := getPublishedIP([]string{}, nil)
4848

4949
So(err, ShouldBeNil)
5050
So(result, ShouldResemble, addresses[0].String())

catalog/services_state.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ func NewServer(name string) *Server {
5353

5454
// Holds the state about all the servers in the cluster
5555
type ServicesState struct {
56-
Servers map[string]*Server
57-
HostnameFn func() (string, error)
58-
Broadcasts chan [][]byte
59-
ServiceNameMatch *regexp.Regexp // How we match service names
60-
LastChanged time.Time
61-
listeners []chan ChangeEvent
56+
Servers map[string]*Server
57+
HostnameFn func() (string, error)
58+
Broadcasts chan [][]byte
59+
ServiceNameMatch *regexp.Regexp // How we match service names
60+
LastChanged time.Time
61+
listeners []chan ChangeEvent
6262
}
6363

6464
// Returns a pointer to a properly configured ServicesState

cli.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import (
88

99
type CliOpts struct {
1010
AdvertiseIP *string
11-
ClusterIPs *[]string
12-
ConfigFile *string
11+
ClusterIPs *[]string
12+
ConfigFile *string
1313
ClusterName *string
1414
}
1515

1616
func exitWithError(err error, message string) {
17-
if err != nil {
18-
log.Fatalf("%s (%s)", message, err.Error())
19-
}
17+
if err != nil {
18+
log.Fatalf("%s (%s)", message, err.Error())
19+
}
2020
}
2121

2222
func parseCommandLine() *CliOpts {
2323
var opts CliOpts
2424

2525
opts.AdvertiseIP = kingpin.Flag("advertise-ip", "The address to advertise to the cluster").Short('a').String()
26-
opts.ClusterIPs = kingpin.Flag("cluster-ip", "The cluster seed addresses").Required().Short('c').Strings()
27-
opts.ConfigFile = kingpin.Flag("config-file", "The config file to use").Short('f').Default("bosun.toml").String()
26+
opts.ClusterIPs = kingpin.Flag("cluster-ip", "The cluster seed addresses").Required().Short('c').Strings()
27+
opts.ConfigFile = kingpin.Flag("config-file", "The config file to use").Short('f').Default("bosun.toml").String()
2828
opts.ClusterName = kingpin.Flag("cluster-name", "The cluster we're part of").Short('n').Default("default").String()
2929
kingpin.Parse()
3030

config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type HAproxyConfig struct {
1212
BindIP string `toml:"bind_ip"`
1313
TemplateFile string `toml:"template_file"`
1414
ConfigFile string `toml:"config_file"`
15-
Disable bool `toml:"disable"`
15+
Disable bool `toml:"disable"`
1616
}
1717

1818
type ServicesConfig struct {
@@ -37,8 +37,8 @@ type Config struct {
3737
Bosun BosunConfig
3838
DockerDiscovery DockerConfig
3939
StaticDiscovery StaticConfig
40-
Services ServicesConfig
41-
HAproxy HAproxyConfig
40+
Services ServicesConfig
41+
HAproxy HAproxyConfig
4242
}
4343

4444
func setDefaults(config *Config) {

discovery/discovery.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (d *MultiDiscovery) Run(quit chan bool) {
5151
for _, q := range quitChans {
5252
// Copy q so we don't change it out from under the goroutine
5353
go func(q chan bool) {
54-
q <-true
54+
q <- true
5555
}(q)
5656
}
5757
}()

discovery/discovery_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
)
99

1010
type mockDiscoverer struct {
11-
ServicesList []service.Service
12-
RunInvoked bool
11+
ServicesList []service.Service
12+
RunInvoked bool
1313
ServicesInvoked bool
14-
Quit chan bool
14+
Quit chan bool
1515
}
1616

1717
func (m *mockDiscoverer) Services() []service.Service {
@@ -37,7 +37,7 @@ func Test_MultiDiscovery(t *testing.T) {
3737
}, false, false, make(chan bool),
3838
}
3939

40-
multi := &MultiDiscovery{[]Discoverer{ disco1, disco2 }}
40+
multi := &MultiDiscovery{[]Discoverer{disco1, disco2}}
4141

4242
Convey("Run() invokes the Run() method for all the discoverers", func() {
4343
multi.Run(make(chan bool))
@@ -49,7 +49,7 @@ func Test_MultiDiscovery(t *testing.T) {
4949
Convey("Run() propagates the quit signal", func() {
5050
quit := make(chan bool, 1)
5151
multi.Run(quit)
52-
quit <-true
52+
quit <- true
5353

5454
So(disco1.RunInvoked, ShouldBeTrue)
5555
So(disco2.RunInvoked, ShouldBeTrue)

discovery/docker_discovery.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,39 @@ const (
1515
)
1616

1717
type DockerDiscovery struct {
18-
events chan *docker.APIEvents // Where events are announced to us
19-
endpoint string // The Docker endpoint to talk to
20-
containers []*service.Service // The list of containers we know about
21-
sync.RWMutex // Reader/Writer lock controlling .containers
18+
events chan *docker.APIEvents // Where events are announced to us
19+
endpoint string // The Docker endpoint to talk to
20+
containers []*service.Service // The list of containers we know about
21+
sync.RWMutex // Reader/Writer lock controlling .containers
2222
}
2323

2424
func NewDockerDiscovery(endpoint string) *DockerDiscovery {
2525
discovery := DockerDiscovery{
2626
endpoint: endpoint,
27-
events: make(chan *docker.APIEvents),
27+
events: make(chan *docker.APIEvents),
2828
}
2929
return &discovery
3030
}
3131

3232
func (d *DockerDiscovery) Run(quit chan bool) {
3333
getContainersQuit := make(chan bool)
34-
watchEventsQuit := make(chan bool)
34+
watchEventsQuit := make(chan bool)
3535
processEventsQuit := make(chan bool)
3636

3737
// Propagate quit channel message
3838
go func() {
3939
<-quit // Block on channel until we get a message
40-
go func() { getContainersQuit <-true }()
41-
go func() { watchEventsQuit <-true }()
42-
go func() { processEventsQuit <-true }()
40+
go func() { getContainersQuit <- true }()
41+
go func() { watchEventsQuit <- true }()
42+
go func() { processEventsQuit <- true }()
4343
}()
4444

4545
// Loop around fetching the whole container list
4646
go func() {
47-
for ;; {
47+
for {
4848
d.getContainers()
4949
select {
50-
case <- getContainersQuit:
50+
case <-getContainersQuit:
5151
return
5252
default:
5353
}
@@ -75,7 +75,7 @@ func (d *DockerDiscovery) Services() []service.Service {
7575
func (d *DockerDiscovery) getContainers() {
7676
// New connection every time
7777
client, _ := docker.NewClient(d.endpoint)
78-
containers, err := client.ListContainers(docker.ListContainersOptions{ All: false })
78+
containers, err := client.ListContainers(docker.ListContainersOptions{All: false})
7979
if err != nil {
8080
return
8181
}
@@ -102,7 +102,7 @@ func (d *DockerDiscovery) watchEvents(quit chan bool) {
102102
if err != nil {
103103
log.Println("Lost connection to Docker, re-connecting")
104104
client.RemoveEventListener(d.events)
105-
d.events = make(chan *docker.APIEvents) // RemoveEventListener closes it
105+
d.events = make(chan *docker.APIEvents) // RemoveEventListener closes it
106106

107107
client, err = docker.NewClient(d.endpoint)
108108
if err == nil {
@@ -113,7 +113,7 @@ func (d *DockerDiscovery) watchEvents(quit chan bool) {
113113
}
114114

115115
select {
116-
case <- quit:
116+
case <-quit:
117117
return
118118
default:
119119
}
@@ -147,7 +147,7 @@ func (d *DockerDiscovery) handleEvent(event docker.APIEvents) {
147147
func (d *DockerDiscovery) processEvents(quit chan bool) {
148148
for {
149149
select {
150-
case <- quit:
150+
case <-quit:
151151
return
152152
default:
153153
}

discovery/docker_discovery_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ func Test_DockerDiscovery(t *testing.T) {
1515

1616
Convey("Working with Docker containers", t, func() {
1717
endpoint := "http://example.com:2375"
18-
disco := NewDockerDiscovery(endpoint)
19-
svcId1 := "deadbeef1231"
20-
svcId2 := "deadbeef1011"
18+
disco := NewDockerDiscovery(endpoint)
19+
svcId1 := "deadbeef1231"
20+
svcId2 := "deadbeef1011"
2121
baseTime := time.Now().UTC().Round(time.Second)
22-
service1 := service.Service{ ID: svcId1, Hostname: hostname, Updated: baseTime }
23-
service2 := service.Service{ ID: svcId2, Hostname: hostname, Updated: baseTime }
24-
services := []*service.Service{ &service1, &service2 }
22+
service1 := service.Service{ID: svcId1, Hostname: hostname, Updated: baseTime}
23+
service2 := service.Service{ID: svcId2, Hostname: hostname, Updated: baseTime}
24+
services := []*service.Service{&service1, &service2}
2525

2626
Convey("New() configures an endpoint and events channel", func() {
2727
So(disco.endpoint, ShouldEqual, endpoint)
@@ -38,7 +38,7 @@ func Test_DockerDiscovery(t *testing.T) {
3838

3939
Convey("handleEvents() prunes dead containers", func() {
4040
disco.containers = services
41-
disco.handleEvent(docker.APIEvents{ID: svcId1, Status:"die"})
41+
disco.handleEvent(docker.APIEvents{ID: svcId1, Status: "die"})
4242

4343
result := disco.Services()
4444
So(len(result), ShouldEqual, 1)

discovery/static_discovery.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ import (
1515

1616
type Target struct {
1717
Service service.Service
18-
Check healthy.Check
18+
Check healthy.Check
1919
}
2020

2121
type StaticDiscovery struct {
22-
Targets []*Target
22+
Targets []*Target
2323
ConfigFile string
2424
HostnameFn func() (string, error)
2525
}
2626

2727
func NewStaticDiscovery(filename string) *StaticDiscovery {
2828
return &StaticDiscovery{
2929
ConfigFile: filename,
30-
HostnameFn: os.Hostname,
30+
HostnameFn: os.Hostname,
3131
}
3232
}
3333

@@ -97,7 +97,7 @@ func RandomHex(count int) ([]byte, error) {
9797
return nil, err
9898
}
9999

100-
encoded := make([]byte, count * 2)
100+
encoded := make([]byte, count*2)
101101
hex.Encode(encoded, raw)
102102
return encoded, nil
103103
}

discovery/static_discovery_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Test_Services(t *testing.T) {
4848
service.Service{ID: "foofoo"},
4949
healthy.Check{ID: "foofoo"},
5050
}
51-
disco.Targets = []*Target{ tgt1, tgt2 }
51+
disco.Targets = []*Target{tgt1, tgt2}
5252

5353
Convey("Returns a list of services extracted from Targets", func() {
5454
services := disco.Services()
@@ -59,7 +59,7 @@ func Test_Services(t *testing.T) {
5959
})
6060

6161
Convey("Updates the current timestamp each time", func() {
62-
services := disco.Services()
62+
services := disco.Services()
6363
services2 := disco.Services()
6464

6565
So(services[0].Updated.Before(services2[0].Updated), ShouldBeTrue)

haproxy/haproxy.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import (
1212
"text/template"
1313
"time"
1414

15-
"github.com/newrelic/bosun/service"
1615
"github.com/newrelic/bosun/catalog"
16+
"github.com/newrelic/bosun/service"
1717
)
1818

1919
type portset map[string]struct{}
2020
type portmap map[string]portset
2121

2222
// Configuration and state for the HAproxy management module
2323
type HAproxy struct {
24-
ReloadCmd string
25-
VerifyCmd string
26-
BindIP string
27-
Template string
24+
ReloadCmd string
25+
VerifyCmd string
26+
BindIP string
27+
Template string
2828
ConfigFile string
2929
}
3030

@@ -45,7 +45,7 @@ func (h *HAproxy) makePortmap(services map[string][]*service.Service) portmap {
4545
ports := make(portmap)
4646

4747
for name, svcList := range services {
48-
if _, ok := ports[name]; !ok {
48+
if _, ok := ports[name]; !ok {
4949
ports[name] = make(portset, 5)
5050
}
5151

@@ -73,15 +73,15 @@ func sanitizeName(image string) string {
7373
// template. Ports are looked up by the func getPorts().
7474
func (h *HAproxy) WriteConfig(state *catalog.ServicesState, output io.Writer) {
7575
services := servicesWithPorts(state)
76-
ports := h.makePortmap(services)
76+
ports := h.makePortmap(services)
7777

7878
data := struct {
7979
Services map[string][]*service.Service
8080
}{
8181
Services: services,
8282
}
8383

84-
funcMap := template.FuncMap{
84+
funcMap := template.FuncMap{
8585
"now": time.Now().UTC,
8686
"getPorts": func(k string) []string {
8787
var keys []string
@@ -90,9 +90,9 @@ func (h *HAproxy) WriteConfig(state *catalog.ServicesState, output io.Writer) {
9090
}
9191
return keys
9292
},
93-
"bindIP": func() string { return h.BindIP },
93+
"bindIP": func() string { return h.BindIP },
9494
"sanitizeName": sanitizeName,
95-
}
95+
}
9696

9797
t, err := template.New("haproxy").Funcs(funcMap).ParseFiles(h.Template)
9898
if err != nil {

0 commit comments

Comments
 (0)