From 643d64776154a0617d687381ca68a19a5f65587b Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Mon, 5 Jan 2015 11:26:23 -0800 Subject: [PATCH 1/2] Gofmt all files. --- client/client_test.go | 2 +- container/docker/handler.go | 2 +- info/machine.go | 2 +- pages/docker.go | 2 +- pages/static/google_jsapi_js.go | 2 +- storage/memory/stats_buffer_test.go | 1 - 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index bf4d9f76..94978720 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -79,7 +79,7 @@ func TestGetMachineinfo(t *testing.T) { NumCores: 8, MemoryCapacity: 31625871360, DiskMap: map[string]info.DiskInfo{ - "8:0": info.DiskInfo{ + "8:0": { Name: "sda", Major: 8, Minor: 0, diff --git a/container/docker/handler.go b/container/docker/handler.go index 4f38b14d..6ec8fdf6 100644 --- a/container/docker/handler.go +++ b/container/docker/handler.go @@ -159,7 +159,7 @@ func (self *dockerContainerHandler) readLibcontainerConfig() (*libcontainer.Conf // Translate the old config into the new config. config = oldConfig.Config - for ns, _ := range oldConfig.OldNamespaces { + for ns := range oldConfig.OldNamespaces { config.Namespaces = append(config.Namespaces, libcontainer.Namespace{ Name: ns, }) diff --git a/info/machine.go b/info/machine.go index 5591f3d2..7371548e 100644 --- a/info/machine.go +++ b/info/machine.go @@ -76,7 +76,7 @@ func (self *Node) AddNodeCache(c Cache) { } func (self *Node) AddPerCoreCache(c Cache) { - for idx, _ := range self.Cores { + for idx := range self.Cores { self.Cores[idx].Caches = append(self.Cores[idx].Caches, c) } } diff --git a/pages/docker.go b/pages/docker.go index 793fb458..30a1b19f 100644 --- a/pages/docker.go +++ b/pages/docker.go @@ -43,7 +43,7 @@ func serveDockerPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error data = &pageData{ DisplayName: dockerContainersText, ParentContainers: []link{ - link{ + { Text: dockerContainersText, Link: DockerPage, }}, diff --git a/pages/static/google_jsapi_js.go b/pages/static/google_jsapi_js.go index 3829b2de..9e319b22 100644 --- a/pages/static/google_jsapi_js.go +++ b/pages/static/google_jsapi_js.go @@ -14,7 +14,7 @@ package static -const googleJsapiJs= ` +const googleJsapiJs = ` if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) { window['google'] = {}; } diff --git a/storage/memory/stats_buffer_test.go b/storage/memory/stats_buffer_test.go index fd1b8e9d..780b15ba 100644 --- a/storage/memory/stats_buffer_test.go +++ b/storage/memory/stats_buffer_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/google/cadvisor/info" - ) func createStats(id int32) *info.ContainerStats { From 60c6e070a5b1fbf6c7aad3942cf00383fb1b3568 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Mon, 5 Jan 2015 11:28:06 -0800 Subject: [PATCH 2/2] Add Travis check for Gofmt. --- .travis.yml | 3 ++- deploy/check_gofmt.sh | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 deploy/check_gofmt.sh diff --git a/.travis.yml b/.travis.yml index 448ae1f6..cb9c78c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ before_script: - sudo service influxdb start script: - export PATH=$PATH:$HOME/gopath/bin + - ./deploy/check_gofmt.sh . + - go vet github.com/google/cadvisor/... - godep go test -v -race -test.short github.com/google/cadvisor/... - godep go build github.com/google/cadvisor - - go vet github.com/google/cadvisor/... diff --git a/deploy/check_gofmt.sh b/deploy/check_gofmt.sh new file mode 100755 index 00000000..34fd9d7c --- /dev/null +++ b/deploy/check_gofmt.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Check usage. +if [ $# -ne 1 ]; then + echo "USAGE: check_gofmt " + exit 1 +fi + +# Check formatting on non Godep'd code. +GOFMT_PATHS=$(find . -not -wholename "*.git*" -not -wholename "*Godeps*" -not -name "." -type d) + +# Find any files with gofmt problems +BAD_FILES=$(gofmt -s -l $GOFMT_PATHS) + +if [ -n "$BAD_FILES" ]; then + echo "The following files are not properly formatted:" + echo $BAD_FILES + exit 1 +fi