Skip to content

Commit

Permalink
Merge pull request #523 from rchirakk/golint
Browse files Browse the repository at this point in the history
add go fmt/lint/vet checks in Makefile
  • Loading branch information
shaleman authored Aug 15, 2016
2 parents 82ab175 + d5f4c50 commit 5d69318
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 77 deletions.
39 changes: 32 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

.PHONY: all all-CI build clean default unit-test release tar
.PHONY: all all-CI build clean default unit-test release tar checks go-version gofmt-src golint-src govet-src

# find all verifiable packages.
# XXX: explore a better way that doesn't need multiple 'find'
PKGS := `find . -mindepth 1 -maxdepth 1 -type d -name '*' | grep -vE '/\..*$\|Godeps|examples|docs|scripts|mgmtfn|bin|vagrant|test|vendor'`
PKGS += `find . -mindepth 2 -maxdepth 2 -type d -name '*'| grep -vE '/\..*$\|Godeps|examples|docs|scripts|bin|vagrant|vendor'`
SHELL := /bin/bash
EXCLUDE_DIRS := bin docs Godeps scripts test vagrant vendor
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS),$(subst /,,$(sort $(dir $(wildcard */)))))
TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contivk8s/
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
HOST_GOROOT := `go env GOROOT`
Expand All @@ -18,6 +17,12 @@ TAR_EXT := tar.bz2
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
TAR_LOC := .
TAR_FILE := $(TAR_LOC)/$(TAR_FILENAME)
GO_MIN_VERSION := 1.5.1
GO_MAX_VERSION := 1.6.2
GO_VERSION := $(shell go version | cut -d' ' -f3 | sed 's/go//')
GOLINT_CMD := golint -set_exit_status
GOFMT_CMD := gofmt -l
GOVET_CMD := go tool vet

all: build unit-test system-test ubuntu-tests

Expand All @@ -37,8 +42,28 @@ default: build
deps:
./scripts/deps

checks:
./scripts/checks "$(PKGS)"
gofmt-src: $(PKG_DIRS)
$(info +++ gofmt $(PKG_DIRS))
@for dir in $?; do $(GOFMT_CMD) $${dir} | grep "go"; [[ $$? -ne 0 ]] || exit 1; done

golint-src: $(PKG_DIRS)
$(info +++ golint $(PKG_DIRS))
@for dir in $?; do $(GOLINT_CMD) $${dir}/... || exit 1;done

govet-src: $(PKG_DIRS)
$(info +++ govet $(PKG_DIRS))
@for dir in $?; do $(GOVET_CMD) $${dir} || exit 1;done

go-version:
$(info +++ check go version)
ifneq ($(GO_VERSION), $(lastword $(sort $(GO_VERSION) $(GO_MIN_VERSION))))
$(error go version check failed, expected >= $(GO_MIN_VERSION), found $(GO_VERSION))
endif
ifneq ($(GO_VERSION), $(firstword $(sort $(GO_VERSION) $(GO_MAX_VERSION))))
$(error go version check failed, expected <= $(GO_MAX_VERSION), found $(GO_VERSION))
endif

checks: go-version gofmt-src golint-src govet-src

# We cannot perform sudo inside a golang, the only reason to split the rules
# here
Expand Down
2 changes: 1 addition & 1 deletion mgmtfn/k8splugin/cniapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CNIPodAttr struct {

// RspAddPod contains the response to the AddPod
type RspAddPod struct {
Result uint `json:result,,omitempty"`
Result uint `json:"result,omitempty"`
EndpointID string `json:"endpointid,omitempty"`
IPAddress string `json:"ipaddress,omitempty"`
ErrMsg string `json:"errmsg,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions mgmtfn/k8splugin/contivk8s/k8s_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
logger "github.com/Sirupsen/logrus"
)

//CNIError : return format from CNI plugin
type CNIError struct {
CNIVersion string `json:"cniVersion"`
Code uint `json:"code"`
Expand Down
69 changes: 0 additions & 69 deletions scripts/checks

This file was deleted.

0 comments on commit 5d69318

Please sign in to comment.