From dfe9c348c9150a56b8f2c94f6d9dee05eb916c03 Mon Sep 17 00:00:00 2001 From: Gil Casadevall Date: Thu, 19 May 2016 13:35:54 +0200 Subject: [PATCH] Linted all go files --- captain.go | 50 ++++++++++++++++++++------------ cmd/captain/cmd.go | 72 +++++++++++++++++++++++----------------------- docker.go | 6 ++-- git.go | 18 ++++++------ 4 files changed, 79 insertions(+), 67 deletions(-) diff --git a/captain.go b/captain.go index 218c146..7549e4d 100644 --- a/captain.go +++ b/captain.go @@ -38,12 +38,12 @@ func Post(config Config, app App) { } type BuildOptions struct { - Config Config - Force bool + Config Config + Force bool All_branches bool - Long_sha bool - Branch_tags bool - Commit_tags bool + Long_sha bool + Branch_tags bool + Commit_tags bool } // Build function compiles the Containers of the project @@ -77,7 +77,7 @@ func Build(opts BuildOptions) { tagImage(app, rev, "latest") // Tag branch image - for _,branch := range getBranches(opts.All_branches) { + for _, branch := range getBranches(opts.All_branches) { res := tagImage(app, rev, branch) if res != nil { os.Exit(TagFailed) @@ -102,7 +102,7 @@ func Build(opts BuildOptions) { tagImage(app, "latest", rev) // Tag branch image - for _,branch := range getBranches(opts.All_branches) { + for _, branch := range getBranches(opts.All_branches) { res := tagImage(app, "latest", branch) if res != nil { os.Exit(TagFailed) @@ -147,7 +147,7 @@ func Push(opts BuildOptions) { } for _, app := range config.GetApps() { - for _,branch := range getBranches(opts.All_branches) { + for _, branch := range getBranches(opts.All_branches) { info("Pushing image %s:%s", app.Image, "latest") execute("docker", "push", app.Image+":"+"latest") if opts.Branch_tags { @@ -168,7 +168,7 @@ func Pull(opts BuildOptions) { config := opts.Config for _, app := range config.GetApps() { - for _,branch := range getBranches(opts.All_branches) { + for _, branch := range getBranches(opts.All_branches) { info("Pulling image %s:%s", app.Image, "latest") execute("docker", "pull", app.Image+":"+"latest") if opts.Branch_tags { @@ -190,29 +190,41 @@ func Purge(opts BuildOptions) { // For each App for _, app := range config.GetApps() { - var tags =[]string{} + var tags = []string{} // Retrieve the list of the existing Image tags - for _,img := range getImages(app) { - tags=append(tags,img.RepoTags...) + for _, img := range getImages(app) { + tags = append(tags, img.RepoTags...) } // Remove from the list: The latest image - for key,tag := range tags { if (tag == app.Image+":latest") { tags=append(tags[:key], tags[key+1:]...) } } + for key, tag := range tags { + if tag == app.Image+":latest" { + tags = append(tags[:key], tags[key+1:]...) + } + } // Remove from the list: The current commit-id - for key,tag := range tags { if (tag == app.Image+":"+getRevision(opts.Long_sha)) { tags=append(tags[:key], tags[key+1:]...) } } + for key, tag := range tags { + if tag == app.Image+":"+getRevision(opts.Long_sha) { + tags = append(tags[:key], tags[key+1:]...) + } + } // Remove from the list: The working-dir git branches - for _,branch := range getBranches(opts.All_branches) { - for key,tag := range tags { if (tag == app.Image+":"+branch) { tags=append(tags[:key], tags[key+1:]...) } } + for _, branch := range getBranches(opts.All_branches) { + for key, tag := range tags { + if tag == app.Image+":"+branch { + tags = append(tags[:key], tags[key+1:]...) + } + } } // Proceed with deletion of Images - for _,tag := range tags { - info ("Deleting image %s", tag) + for _, tag := range tags { + info("Deleting image %s", tag) res := removeImage(tag) - if (res != nil) { + if res != nil { err("Deleting image failed: %s", res) os.Exit(DeleteImageFailed) } diff --git a/cmd/captain/cmd.go b/cmd/captain/cmd.go index cb3225d..a6da044 100644 --- a/cmd/captain/cmd.go +++ b/cmd/captain/cmd.go @@ -11,17 +11,17 @@ import ( // Options that are passed by CLI are mapped here for consumption type Options struct { - debug bool - force bool - long_sha bool - namespace string - config string - images []string + debug bool + force bool + long_sha bool + namespace string + config string + images []string // Options to define the docker tags context all_branches bool - branch_tags bool - commit_tags bool + branch_tags bool + commit_tags bool } var options Options @@ -40,12 +40,12 @@ func handleCmd() { } buildOpts := captain.BuildOptions{ - Config: config, - Force: options.force, - All_branches: options.all_branches, - Long_sha: options.long_sha, - Branch_tags: options.branch_tags, - Commit_tags: options.commit_tags, + Config: config, + Force: options.force, + All_branches: options.all_branches, + Long_sha: options.long_sha, + Branch_tags: options.branch_tags, + Commit_tags: options.commit_tags, } captain.Build(buildOpts) @@ -64,12 +64,12 @@ func handleCmd() { } buildOpts := captain.BuildOptions{ - Config: config, - Force: options.force, - All_branches: options.all_branches, - Long_sha: options.long_sha, - Branch_tags: options.branch_tags, - Commit_tags: options.commit_tags, + Config: config, + Force: options.force, + All_branches: options.all_branches, + Long_sha: options.long_sha, + Branch_tags: options.branch_tags, + Commit_tags: options.commit_tags, } // Build everything before testing @@ -90,12 +90,12 @@ func handleCmd() { } buildOpts := captain.BuildOptions{ - Config: config, - Force: options.force, - All_branches: options.all_branches, - Long_sha: options.long_sha, - Branch_tags: options.branch_tags, - Commit_tags: options.commit_tags, + Config: config, + Force: options.force, + All_branches: options.all_branches, + Long_sha: options.long_sha, + Branch_tags: options.branch_tags, + Commit_tags: options.commit_tags, } // Build everything before pushing @@ -116,12 +116,12 @@ func handleCmd() { } buildOpts := captain.BuildOptions{ - Config: config, - Force: options.force, - All_branches: options.all_branches, - Long_sha: options.long_sha, - Branch_tags: options.branch_tags, - Commit_tags: options.commit_tags, + Config: config, + Force: options.force, + All_branches: options.all_branches, + Long_sha: options.long_sha, + Branch_tags: options.branch_tags, + Commit_tags: options.commit_tags, } captain.Pull(buildOpts) @@ -140,10 +140,10 @@ func handleCmd() { } buildOpts := captain.BuildOptions{ - Config: config, - Force: options.force, - All_branches: options.all_branches, - Long_sha: options.long_sha, + Config: config, + Force: options.force, + All_branches: options.all_branches, + Long_sha: options.long_sha, } captain.Purge(buildOpts) diff --git a/docker.go b/docker.go index 1b41044..8be97a9 100644 --- a/docker.go +++ b/docker.go @@ -70,9 +70,9 @@ func removeImage(name string) error { /** * Retrieves a list of existing Images for the specific App. */ -func getImages(app App) ([]docker.APIImages) { +func getImages(app App) []docker.APIImages { debug("Getting images %s", app.Image) - imgs, _ := client.ListImages(docker.ListImagesOptions{All: false, Filter: app.Image}) + imgs, _ := client.ListImages(docker.ListImagesOptions{All: false, Filter: app.Image}) return imgs } @@ -83,4 +83,4 @@ func imageExist(app App, tag string) bool { return true } return false -} \ No newline at end of file +} diff --git a/git.go b/git.go index 25a637c..efbf15c 100644 --- a/git.go +++ b/git.go @@ -18,31 +18,31 @@ func getRevision(long_sha bool) string { func getBranches(all_branches bool) []string { // Labels (branches + tags) - var labels =[]string{} + var labels = []string{} branches_str, _ := oneliner("git", "name-rev", "--name-only", "HEAD") - if (all_branches) { - branches_str,_ = oneliner("git", "branch", "--no-column", "--contains", "HEAD") + if all_branches { + branches_str, _ = oneliner("git", "branch", "--no-column", "--contains", "HEAD") } var branches = make([]string, 5) - if (branches_str != "") { + if branches_str != "" { // Remove asterisk from branches list r := regexp.MustCompile("[\\* ] ") branches_str = r.ReplaceAllString(branches_str, "") branches = strings.Split(branches_str, "\n") - + // Branches list is separated by spaces. Let's put it in an array - labels=append(labels,branches...) + labels = append(labels, branches...) } tags_str, _ := oneliner("git", "tag", "--points-at", "HEAD") - if (tags_str != "") { + if tags_str != "" { tags := strings.Split(tags_str, "\n") debug("Active branches %s and tags %s", branches, tags) // Git tag list is separated by multi-lines. Let's put it in an array - labels=append(labels,tags...) + labels = append(labels, tags...) } for key := range labels { @@ -60,7 +60,7 @@ func getBranches(all_branches bool) []string { // Replace all "~" with "." labels[key] = strings.Replace(labels[key], "~", ".", -1) } - + return labels }