Skip to content

Commit e2e99ef

Browse files
committed
add gofmt, golint and go vet checks (contiv#13)
1 parent 3ed0b89 commit e2e99ef

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test: start build
1919
vagrant ssh node1 -c 'cd /opt/gopath/src/github.com/contiv/objdb && make host-test'
2020

2121
host-build:
22+
./checks "./*.go ./modeldb"
2223
go get github.com/tools/godep
2324
godep go install ./ ./modeldb
2425

checks

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
#performs basic dev and build environment checks
4+
5+
USAGE="Usage: $0 <build packages>"
6+
7+
if [ $# -ne 1 ]; then
8+
echo $USAGE
9+
exit 1
10+
fi
11+
12+
BUILD_PKGS=$1
13+
14+
if ! go get github.com/golang/lint/golint
15+
then
16+
echo "!!! Could not install golint"
17+
exit 1
18+
fi
19+
20+
echo "+++ Checking gofmt..."
21+
fmtRes=$(gofmt -l $BUILD_PKGS)
22+
if [ -n "${fmtRes}" ]; then
23+
echo -e "!!! gofmt checking failed:\n${fmtRes}\n"
24+
exit 1
25+
fi
26+
27+
echo "+++ golint tree..."
28+
for i in ${BUILD_PKGS}
29+
do
30+
tmp="$(golint ${i})"
31+
if [ -n "$tmp" ]
32+
then
33+
lintOutput="${lintOutput}\n${tmp}" # golint has no exit codes
34+
fi
35+
done
36+
37+
if [ -n "${lintOutput}" ]
38+
then
39+
echo -e "!!! golint checking failed:\n${lintOutput}\n"
40+
exit 1
41+
fi
42+
43+
echo "+++ go vet tree..."
44+
for i in ${BUILD_PKGS}
45+
do
46+
tmp="$(go vet ${i} 2>&1)"
47+
if [ -n "$tmp" ]
48+
then
49+
vetOutput="${vetOutput}\n${tmp}"
50+
fi
51+
done
52+
53+
if [ -n "${vetOutput}" ]
54+
then
55+
echo -e "!!! go vet checking failed:\n${vetOutput}\n"
56+
exit 1
57+
fi
58+
59+
echo "+++ All checks passed!!"
60+
exit 0

etcdClient.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type etcdPlugin struct {
3333
mutex *sync.Mutex
3434
}
3535

36+
// EtcdClient has etcd client state
3637
type EtcdClient struct {
3738
client client.Client // etcd client
3839
kapi client.KeysAPI
@@ -94,7 +95,7 @@ func (ep *etcdPlugin) NewClient(endpoints []string) (API, error) {
9495
return ec, nil
9596
}
9697

97-
// Get an object
98+
// GetObj Get an object
9899
func (ep *EtcdClient) GetObj(key string, retVal interface{}) error {
99100
keyName := "/contiv.io/obj/" + key
100101

@@ -128,7 +129,7 @@ func recursAddNode(node *client.Node, list []string) []string {
128129
return list
129130
}
130131

131-
// Get a list of objects in a directory
132+
// ListDir Get a list of objects in a directory
132133
func (ep *EtcdClient) ListDir(key string) ([]string, error) {
133134
keyName := "/contiv.io/obj/" + key
134135

@@ -159,7 +160,7 @@ func (ep *EtcdClient) ListDir(key string) ([]string, error) {
159160
return retList, nil
160161
}
161162

162-
// Save an object, create if it doesnt exist
163+
// SetObj Save an object, create if it doesnt exist
163164
func (ep *EtcdClient) SetObj(key string, value interface{}) error {
164165
keyName := "/contiv.io/obj/" + key
165166

@@ -179,7 +180,7 @@ func (ep *EtcdClient) SetObj(key string, value interface{}) error {
179180
return nil
180181
}
181182

182-
// Remove an object
183+
// DelObj Remove an object
183184
func (ep *EtcdClient) DelObj(key string) error {
184185
keyName := "/contiv.io/obj/" + key
185186

@@ -215,7 +216,7 @@ func httpGetJSON(url string, data interface{}) (interface{}, error) {
215216
return data, nil
216217
}
217218

218-
// Return the local address where etcd is listening
219+
// GetLocalAddr Return the local address where etcd is listening
219220
func (ep *EtcdClient) GetLocalAddr() (string, error) {
220221
var epData struct {
221222
Name string `json:"name"`

0 commit comments

Comments
 (0)