Skip to content

Commit dfe9c34

Browse files
committed
Linted all go files
1 parent 9824a9e commit dfe9c34

File tree

4 files changed

+79
-67
lines changed

4 files changed

+79
-67
lines changed

captain.go

+31-19
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ func Post(config Config, app App) {
3838
}
3939

4040
type BuildOptions struct {
41-
Config Config
42-
Force bool
41+
Config Config
42+
Force bool
4343
All_branches bool
44-
Long_sha bool
45-
Branch_tags bool
46-
Commit_tags bool
44+
Long_sha bool
45+
Branch_tags bool
46+
Commit_tags bool
4747
}
4848

4949
// Build function compiles the Containers of the project
@@ -77,7 +77,7 @@ func Build(opts BuildOptions) {
7777
tagImage(app, rev, "latest")
7878

7979
// Tag branch image
80-
for _,branch := range getBranches(opts.All_branches) {
80+
for _, branch := range getBranches(opts.All_branches) {
8181
res := tagImage(app, rev, branch)
8282
if res != nil {
8383
os.Exit(TagFailed)
@@ -102,7 +102,7 @@ func Build(opts BuildOptions) {
102102
tagImage(app, "latest", rev)
103103

104104
// Tag branch image
105-
for _,branch := range getBranches(opts.All_branches) {
105+
for _, branch := range getBranches(opts.All_branches) {
106106
res := tagImage(app, "latest", branch)
107107
if res != nil {
108108
os.Exit(TagFailed)
@@ -147,7 +147,7 @@ func Push(opts BuildOptions) {
147147
}
148148

149149
for _, app := range config.GetApps() {
150-
for _,branch := range getBranches(opts.All_branches) {
150+
for _, branch := range getBranches(opts.All_branches) {
151151
info("Pushing image %s:%s", app.Image, "latest")
152152
execute("docker", "push", app.Image+":"+"latest")
153153
if opts.Branch_tags {
@@ -168,7 +168,7 @@ func Pull(opts BuildOptions) {
168168
config := opts.Config
169169

170170
for _, app := range config.GetApps() {
171-
for _,branch := range getBranches(opts.All_branches) {
171+
for _, branch := range getBranches(opts.All_branches) {
172172
info("Pulling image %s:%s", app.Image, "latest")
173173
execute("docker", "pull", app.Image+":"+"latest")
174174
if opts.Branch_tags {
@@ -190,29 +190,41 @@ func Purge(opts BuildOptions) {
190190

191191
// For each App
192192
for _, app := range config.GetApps() {
193-
var tags =[]string{}
193+
var tags = []string{}
194194

195195
// Retrieve the list of the existing Image tags
196-
for _,img := range getImages(app) {
197-
tags=append(tags,img.RepoTags...)
196+
for _, img := range getImages(app) {
197+
tags = append(tags, img.RepoTags...)
198198
}
199199

200200
// Remove from the list: The latest image
201-
for key,tag := range tags { if (tag == app.Image+":latest") { tags=append(tags[:key], tags[key+1:]...) } }
201+
for key, tag := range tags {
202+
if tag == app.Image+":latest" {
203+
tags = append(tags[:key], tags[key+1:]...)
204+
}
205+
}
202206

203207
// Remove from the list: The current commit-id
204-
for key,tag := range tags { if (tag == app.Image+":"+getRevision(opts.Long_sha)) { tags=append(tags[:key], tags[key+1:]...) } }
208+
for key, tag := range tags {
209+
if tag == app.Image+":"+getRevision(opts.Long_sha) {
210+
tags = append(tags[:key], tags[key+1:]...)
211+
}
212+
}
205213

206214
// Remove from the list: The working-dir git branches
207-
for _,branch := range getBranches(opts.All_branches) {
208-
for key,tag := range tags { if (tag == app.Image+":"+branch) { tags=append(tags[:key], tags[key+1:]...) } }
215+
for _, branch := range getBranches(opts.All_branches) {
216+
for key, tag := range tags {
217+
if tag == app.Image+":"+branch {
218+
tags = append(tags[:key], tags[key+1:]...)
219+
}
220+
}
209221
}
210222

211223
// Proceed with deletion of Images
212-
for _,tag := range tags {
213-
info ("Deleting image %s", tag)
224+
for _, tag := range tags {
225+
info("Deleting image %s", tag)
214226
res := removeImage(tag)
215-
if (res != nil) {
227+
if res != nil {
216228
err("Deleting image failed: %s", res)
217229
os.Exit(DeleteImageFailed)
218230
}

cmd/captain/cmd.go

+36-36
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import (
1111

1212
// Options that are passed by CLI are mapped here for consumption
1313
type Options struct {
14-
debug bool
15-
force bool
16-
long_sha bool
17-
namespace string
18-
config string
19-
images []string
14+
debug bool
15+
force bool
16+
long_sha bool
17+
namespace string
18+
config string
19+
images []string
2020

2121
// Options to define the docker tags context
2222
all_branches bool
23-
branch_tags bool
24-
commit_tags bool
23+
branch_tags bool
24+
commit_tags bool
2525
}
2626

2727
var options Options
@@ -40,12 +40,12 @@ func handleCmd() {
4040
}
4141

4242
buildOpts := captain.BuildOptions{
43-
Config: config,
44-
Force: options.force,
45-
All_branches: options.all_branches,
46-
Long_sha: options.long_sha,
47-
Branch_tags: options.branch_tags,
48-
Commit_tags: options.commit_tags,
43+
Config: config,
44+
Force: options.force,
45+
All_branches: options.all_branches,
46+
Long_sha: options.long_sha,
47+
Branch_tags: options.branch_tags,
48+
Commit_tags: options.commit_tags,
4949
}
5050

5151
captain.Build(buildOpts)
@@ -64,12 +64,12 @@ func handleCmd() {
6464
}
6565

6666
buildOpts := captain.BuildOptions{
67-
Config: config,
68-
Force: options.force,
69-
All_branches: options.all_branches,
70-
Long_sha: options.long_sha,
71-
Branch_tags: options.branch_tags,
72-
Commit_tags: options.commit_tags,
67+
Config: config,
68+
Force: options.force,
69+
All_branches: options.all_branches,
70+
Long_sha: options.long_sha,
71+
Branch_tags: options.branch_tags,
72+
Commit_tags: options.commit_tags,
7373
}
7474

7575
// Build everything before testing
@@ -90,12 +90,12 @@ func handleCmd() {
9090
}
9191

9292
buildOpts := captain.BuildOptions{
93-
Config: config,
94-
Force: options.force,
95-
All_branches: options.all_branches,
96-
Long_sha: options.long_sha,
97-
Branch_tags: options.branch_tags,
98-
Commit_tags: options.commit_tags,
93+
Config: config,
94+
Force: options.force,
95+
All_branches: options.all_branches,
96+
Long_sha: options.long_sha,
97+
Branch_tags: options.branch_tags,
98+
Commit_tags: options.commit_tags,
9999
}
100100

101101
// Build everything before pushing
@@ -116,12 +116,12 @@ func handleCmd() {
116116
}
117117

118118
buildOpts := captain.BuildOptions{
119-
Config: config,
120-
Force: options.force,
121-
All_branches: options.all_branches,
122-
Long_sha: options.long_sha,
123-
Branch_tags: options.branch_tags,
124-
Commit_tags: options.commit_tags,
119+
Config: config,
120+
Force: options.force,
121+
All_branches: options.all_branches,
122+
Long_sha: options.long_sha,
123+
Branch_tags: options.branch_tags,
124+
Commit_tags: options.commit_tags,
125125
}
126126

127127
captain.Pull(buildOpts)
@@ -140,10 +140,10 @@ func handleCmd() {
140140
}
141141

142142
buildOpts := captain.BuildOptions{
143-
Config: config,
144-
Force: options.force,
145-
All_branches: options.all_branches,
146-
Long_sha: options.long_sha,
143+
Config: config,
144+
Force: options.force,
145+
All_branches: options.all_branches,
146+
Long_sha: options.long_sha,
147147
}
148148

149149
captain.Purge(buildOpts)

docker.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ func removeImage(name string) error {
7070
/**
7171
* Retrieves a list of existing Images for the specific App.
7272
*/
73-
func getImages(app App) ([]docker.APIImages) {
73+
func getImages(app App) []docker.APIImages {
7474
debug("Getting images %s", app.Image)
75-
imgs, _ := client.ListImages(docker.ListImagesOptions{All: false, Filter: app.Image})
75+
imgs, _ := client.ListImages(docker.ListImagesOptions{All: false, Filter: app.Image})
7676
return imgs
7777
}
7878

@@ -83,4 +83,4 @@ func imageExist(app App, tag string) bool {
8383
return true
8484
}
8585
return false
86-
}
86+
}

git.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ func getRevision(long_sha bool) string {
1818

1919
func getBranches(all_branches bool) []string {
2020
// Labels (branches + tags)
21-
var labels =[]string{}
21+
var labels = []string{}
2222

2323
branches_str, _ := oneliner("git", "name-rev", "--name-only", "HEAD")
24-
if (all_branches) {
25-
branches_str,_ = oneliner("git", "branch", "--no-column", "--contains", "HEAD")
24+
if all_branches {
25+
branches_str, _ = oneliner("git", "branch", "--no-column", "--contains", "HEAD")
2626
}
2727

2828
var branches = make([]string, 5)
29-
if (branches_str != "") {
29+
if branches_str != "" {
3030
// Remove asterisk from branches list
3131
r := regexp.MustCompile("[\\* ] ")
3232
branches_str = r.ReplaceAllString(branches_str, "")
3333
branches = strings.Split(branches_str, "\n")
34-
34+
3535
// Branches list is separated by spaces. Let's put it in an array
36-
labels=append(labels,branches...)
36+
labels = append(labels, branches...)
3737
}
3838

3939
tags_str, _ := oneliner("git", "tag", "--points-at", "HEAD")
4040

41-
if (tags_str != "") {
41+
if tags_str != "" {
4242
tags := strings.Split(tags_str, "\n")
4343
debug("Active branches %s and tags %s", branches, tags)
4444
// Git tag list is separated by multi-lines. Let's put it in an array
45-
labels=append(labels,tags...)
45+
labels = append(labels, tags...)
4646
}
4747

4848
for key := range labels {
@@ -60,7 +60,7 @@ func getBranches(all_branches bool) []string {
6060
// Replace all "~" with "."
6161
labels[key] = strings.Replace(labels[key], "~", ".", -1)
6262
}
63-
63+
6464
return labels
6565
}
6666

0 commit comments

Comments
 (0)