Skip to content

Commit 43d66a3

Browse files
committed
style: linting with staticcheck
1 parent 79abcab commit 43d66a3

File tree

8 files changed

+80
-83
lines changed

8 files changed

+80
-83
lines changed

cmd/docker-gen/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88
"path/filepath"
9-
"sync"
109

1110
"github.com/BurntSushi/toml"
1211
docker "github.com/fsouza/go-dockerclient"
@@ -36,8 +35,6 @@ var (
3635
tlsKey string
3736
tlsCaCert string
3837
tlsVerify bool
39-
tlsCertPath string
40-
wg sync.WaitGroup
4138
)
4239

4340
func (strings *stringslice) String() string {

internal/dockergen/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func ParseWait(s string) (*Wait, error) {
7373
return nil, err
7474
}
7575
if max < min {
76-
return nil, errors.New("Invalid wait interval: max must be larger than min")
76+
return nil, errors.New("invalid wait interval: max must be larger than min")
7777
}
7878
} else {
7979
max = 4 * min

internal/dockergen/docker_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func parseHost(addr string) (string, string, error) {
4848
addr = strings.TrimSpace(addr)
4949
switch {
5050
case addr == "tcp://":
51-
return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
51+
return "", "", fmt.Errorf("invalid bind address format: %s", addr)
5252
case strings.HasPrefix(addr, "unix://"):
5353
proto = "unix"
5454
addr = strings.TrimPrefix(addr, "unix://")
@@ -65,15 +65,15 @@ func parseHost(addr string) (string, string, error) {
6565
addr = "/var/run/docker.sock"
6666
default:
6767
if strings.Contains(addr, "://") {
68-
return "", "", fmt.Errorf("Invalid bind address protocol: %s", addr)
68+
return "", "", fmt.Errorf("invalid bind address protocol: %s", addr)
6969
}
7070
proto = "tcp"
7171
}
7272

7373
if proto != "unix" && strings.Contains(addr, ":") {
7474
hostParts := strings.Split(addr, ":")
7575
if len(hostParts) != 2 {
76-
return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
76+
return "", "", fmt.Errorf("invalid bind address format: %s", addr)
7777
}
7878
if hostParts[0] != "" {
7979
host = hostParts[0]
@@ -84,11 +84,11 @@ func parseHost(addr string) (string, string, error) {
8484
if p, err := strconv.Atoi(hostParts[1]); err == nil && p != 0 {
8585
port = p
8686
} else {
87-
return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
87+
return "", "", fmt.Errorf("invalid bind address format: %s", addr)
8888
}
8989

9090
} else if proto == "tcp" && !strings.Contains(addr, ":") {
91-
return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
91+
return "", "", fmt.Errorf("invalid bind address format: %s", addr)
9292
} else {
9393
host = addr
9494
}

internal/dockergen/generator.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"github.com/fsouza/go-dockerclient"
14+
docker "github.com/fsouza/go-dockerclient"
1515
)
1616

1717
type generator struct {
@@ -41,12 +41,12 @@ type GeneratorConfig struct {
4141
func NewGenerator(gc GeneratorConfig) (*generator, error) {
4242
endpoint, err := GetEndpoint(gc.Endpoint)
4343
if err != nil {
44-
return nil, fmt.Errorf("Bad endpoint: %s", err)
44+
return nil, fmt.Errorf("bad endpoint: %s", err)
4545
}
4646

4747
client, err := NewDockerClient(endpoint, gc.TLSVerify, gc.TLSCert, gc.TLSCACert, gc.TLSKey)
4848
if err != nil {
49-
return nil, fmt.Errorf("Unable to create docker client: %s", err)
49+
return nil, fmt.Errorf("unable to create docker client: %s", err)
5050
}
5151

5252
apiVersion, err := client.Version()
@@ -191,7 +191,7 @@ func (g *generator) generateFromEvents() {
191191
watchers = append(watchers, watcher)
192192

193193
debouncedChan := newDebounceChannel(watcher, config.Wait)
194-
for _ = range debouncedChan {
194+
for range debouncedChan {
195195
containers, err := g.getContainers()
196196
if err != nil {
197197
log.Printf("Error listing containers: %s\n", err)
@@ -367,7 +367,8 @@ func (g *generator) getContainers() ([]*RuntimeContainer, error) {
367367

368368
containers := []*RuntimeContainer{}
369369
for _, apiContainer := range apiContainers {
370-
container, err := g.Client.InspectContainer(apiContainer.ID)
370+
opts := docker.InspectContainerOptions{ID: apiContainer.ID}
371+
container, err := g.Client.InspectContainerWithOptions(opts)
371372
if err != nil {
372373
log.Printf("Error inspecting container: %s: %s\n", apiContainer.ID, err)
373374
continue
@@ -465,7 +466,7 @@ func (g *generator) getContainers() ([]*RuntimeContainer, error) {
465466

466467
func newSignalChannel() <-chan os.Signal {
467468
sig := make(chan os.Signal, 1)
468-
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL)
469+
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
469470

470471
return sig
471472
}

internal/dockergen/generator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/fsouza/go-dockerclient"
15+
docker "github.com/fsouza/go-dockerclient"
1616
dockertest "github.com/fsouza/go-dockerclient/testing"
1717
)
1818

@@ -49,7 +49,7 @@ func TestGenerateFromEvents(t *testing.T) {
4949
}))
5050
server.CustomHandler("/containers/json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5151
result := []docker.APIContainers{
52-
docker.APIContainers{
52+
{
5353
ID: containerID,
5454
Image: "base:latest",
5555
Command: "/bin/sh",
@@ -87,7 +87,7 @@ func TestGenerateFromEvents(t *testing.T) {
8787
},
8888
Image: "0ff407d5a7d9ed36acdf3e75de8cc127afecc9af234d05486be2981cdc01a38d",
8989
NetworkSettings: &docker.NetworkSettings{
90-
IPAddress: fmt.Sprintf("10.0.0.10"),
90+
IPAddress: "10.0.0.10",
9191
IPPrefixLen: 24,
9292
Gateway: "10.0.0.1",
9393
Bridge: "docker0",
@@ -147,24 +147,24 @@ func TestGenerateFromEvents(t *testing.T) {
147147
Endpoint: serverURL,
148148
Configs: ConfigFile{
149149
[]Config{
150-
Config{
150+
{
151151
Template: tmplFile.Name(),
152152
Dest: destFiles[0].Name(),
153153
Watch: false,
154154
},
155-
Config{
155+
{
156156
Template: tmplFile.Name(),
157157
Dest: destFiles[1].Name(),
158158
Watch: true,
159159
Wait: &Wait{0, 0},
160160
},
161-
Config{
161+
{
162162
Template: tmplFile.Name(),
163163
Dest: destFiles[2].Name(),
164164
Watch: true,
165165
Wait: &Wait{20 * time.Millisecond, 25 * time.Millisecond},
166166
},
167-
Config{
167+
{
168168
Template: tmplFile.Name(),
169169
Dest: destFiles[3].Name(),
170170
Watch: true,

internal/dockergen/reflect_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ func TestDeepGetNoPath(t *testing.T) {
1313
t.Fail()
1414
}
1515

16-
var returned RuntimeContainer
17-
returned = value.(RuntimeContainer)
16+
returned := value.(RuntimeContainer)
1817
if !returned.Equals(item) {
1918
t.Fail()
2019
}

internal/dockergen/template.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func getArrayValues(funcName string, entries interface{}) (*reflect.Value, error
4545
case reflect.Array, reflect.Slice:
4646
break
4747
default:
48-
return nil, fmt.Errorf("Must pass an array or slice to '%v'; received %v; kind %v", funcName, entries, kind)
48+
return nil, fmt.Errorf("must pass an array or slice to '%v'; received %v; kind %v", funcName, entries, kind)
4949
}
5050
return &entriesVal, nil
5151
}
@@ -121,7 +121,7 @@ func groupByLabel(entries interface{}, label string) (map[string][]interface{},
121121
}
122122
return nil, nil
123123
}
124-
return nil, fmt.Errorf("Must pass an array or slice of RuntimeContainer to 'groupByLabel'; received %v", v)
124+
return nil, fmt.Errorf("must pass an array or slice of RuntimeContainer to 'groupByLabel'; received %v", v)
125125
}
126126
return generalizedGroupBy("groupByLabel", entries, getLabel, func(groups map[string][]interface{}, value interface{}, v interface{}) {
127127
groups[value.(string)] = append(groups[value.(string)], v)
@@ -261,7 +261,7 @@ func keys(input interface{}) (interface{}, error) {
261261

262262
val := reflect.ValueOf(input)
263263
if val.Kind() != reflect.Map {
264-
return nil, fmt.Errorf("Cannot call keys on a non-map value: %v", input)
264+
return nil, fmt.Errorf("cannot call keys on a non-map value: %v", input)
265265
}
266266

267267
vk := val.MapKeys()
@@ -534,7 +534,7 @@ func GenerateFile(config Config, containers Context) bool {
534534
log.Fatalf("Unable to create empty destination file: %s\n", err)
535535
} else {
536536
emptyFile.Close()
537-
fi, err = os.Stat(config.Dest)
537+
fi, _ = os.Stat(config.Dest)
538538
}
539539
}
540540
if err := dest.Chmod(fi.Mode()); err != nil {
@@ -549,7 +549,7 @@ func GenerateFile(config Config, containers Context) bool {
549549
}
550550
}
551551

552-
if bytes.Compare(oldContents, contents) != 0 {
552+
if !bytes.Equal(oldContents, contents) {
553553
err = os.Rename(dest.Name(), config.Dest)
554554
if err != nil {
555555
log.Fatalf("Unable to create dest file %s: %s\n", config.Dest, err)

0 commit comments

Comments
 (0)