Skip to content

Commit 7390da9

Browse files
committed
style(pkg): use go lint
1 parent de54d86 commit 7390da9

15 files changed

Lines changed: 74 additions & 51 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
rootfs/bin/boot
22
vendor/*
3+
coverage.txt

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ notifications:
99
slack:
1010
rooms:
1111
- drycc:xKmLlmJR4hfRAgVIOwdpAoC9#drycc
12+
after_success:
13+
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ all: build test
2626

2727
build:
2828
${DEV_ENV_CMD} go build ${PKG_DIRS}
29-
30-
test:
29+
test-cover:
30+
${DEV_ENV_CMD} test-cover.sh
31+
test-style:
32+
${DEV_ENV_CMD} lint
33+
test: build test-style test-cover
3134
${DEV_ENV_CMD} go test ${PKG_DIRS}
3235

33-
3436
.PHONY: all build test

aboutme/aboutme.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
"os"
1818
"strings"
1919

20+
v1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
"k8s.io/apimachinery/pkg/labels"
2223
"k8s.io/client-go/kubernetes"
2324
"k8s.io/client-go/rest"
24-
v1 "k8s.io/api/core/v1"
2525
)
2626

2727
// DefaultNamespace is the Kubernetes default namespace.
@@ -38,8 +38,9 @@ var (
3838
EnvName = "POD_NAME"
3939
)
4040

41+
// Me struct is current kuber info
4142
type Me struct {
42-
ApiServer, Name string
43+
APIServer, Name string
4344
IP, NodeIP, Namespace, SelfLink, UID string
4445
Labels map[string]string
4546
Annotations map[string]string
@@ -64,7 +65,7 @@ func FromEnv() (*Me, error) {
6465
url := proto + "://" + host + ":" + port
6566

6667
me := &Me{
67-
ApiServer: url,
68+
APIServer: url,
6869
Name: name,
6970
Namespace: NamespaceFromEnv(),
7071
}
@@ -83,7 +84,7 @@ func FromEnv() (*Me, error) {
8384
return me, err
8485
}
8586

86-
return me, nil
87+
return me, err
8788
}
8889

8990
// Client returns an initialized Kubernetes API client.
@@ -122,7 +123,7 @@ func NamespaceFromEnv() string {
122123
// - Annotations become MY_ANNOTATION_[NAME] = [value]
123124
func (me *Me) ShuntEnv() {
124125
env := map[string]string{
125-
"MY_APISERVER": me.ApiServer,
126+
"MY_APISERVER": me.APIServer,
126127
"MY_NAME": me.Name,
127128
"MY_IP": me.IP,
128129
"MY_NODEIP": me.NodeIP,
@@ -156,7 +157,7 @@ func (me *Me) init() error {
156157
me.SelfLink = p.SelfLink
157158
me.UID = string(p.UID)
158159
me.Labels = p.Labels
159-
me.Annotations = me.Annotations
160+
me.Annotations = p.Annotations
160161

161162
// FIXME: It appears that sometimes the k8s API server does not set the
162163
// PodIP, even though the pod is issued an IP. We need to figure out why,
@@ -230,6 +231,8 @@ func MyIP() (string, error) {
230231

231232
return "0.0.0.0", err
232233
}
234+
235+
// IPByInterface is get ip by device interface
233236
func IPByInterface(name string) (string, error) {
234237
iface, err := net.InterfaceByName(name)
235238
if err != nil {
@@ -248,7 +251,7 @@ func IPByInterface(name string) (string, error) {
248251
}
249252
}
250253
if len(ip) == 0 {
251-
return ip, errors.New("Found no IPv4 addresses.")
254+
return ip, errors.New("found no IPv4 addresses")
252255
}
253256
return ip, nil
254257
}

env/envvar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Get(c cookoo.Context, params *cookoo.Params) (interface{}, cookoo.Interrupt
5555
// - content (string): The given string to expand.
5656
//
5757
// Returns:
58-
// - The expanded string. This expands against the os environemnt (os.ExpandEnv).
58+
// - The expanded string. This expands against the os environment (os.ExpandEnv).
5959
func Expand(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
6060
s := p.Get("content", "").(string)
6161

etcd/discovery/discovery.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* Package discovery contains utlities for Etcd discovery. */
21
package discovery
32

43
import (
@@ -8,10 +7,16 @@ import (
87
"github.com/Masterminds/cookoo"
98
)
109

10+
// TokenFile for etcd
1111
var TokenFile = "/var/run/secrets/drycc/etcd/discovery/token"
1212

13+
// ClusterDiscoveryURL for drycc
1314
const ClusterDiscoveryURL = "http://%s:%s/v2/keys/drycc/discovery/%s"
15+
16+
// ClusterSizeKey for discovery
1417
const ClusterSizeKey = "drycc/discovery/%s/_config/size"
18+
19+
// ClusterStatusKey for drycc
1520
const ClusterStatusKey = "drycc/status/%s/%s"
1621

1722
// Token reads the discovery token from the TokenFile and returns it.

etcd/etcd.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func SimpleGet(cli client.Client, key string, recursive bool) (*client.Response,
6565
return k.Get(dctx(), key, &client.GetOptions{Recursive: recursive})
6666
}
6767

68+
// SimpleSet performs the common base-line set, using a default context.
6869
func SimpleSet(cli client.Client, key, value string, expires time.Duration) (*client.Response, error) {
6970
k := client.NewKeysAPI(cli)
7071
return k.Set(dctx(), key, value, &client.SetOptions{TTL: expires})
@@ -84,7 +85,7 @@ func SimpleSet(cli client.Client, key, value string, expires time.Duration) (*cl
8485
func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
8586
cli, ok := p.Has("client")
8687
if !ok {
87-
return nil, errors.New("No Etcd client found.")
88+
return nil, errors.New("no etcd client found")
8889
}
8990
ec := cli.(client.Client)
9091
path := p.Get("path", "/").(string)
@@ -98,7 +99,7 @@ func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
9899
}
99100

100101
if !res.Node.Dir {
101-
return res, fmt.Errorf("Expected / to be a dir.")
102+
return res, fmt.Errorf("expected / to be a dir")
102103
}
103104
return res, nil
104105
}
@@ -126,7 +127,7 @@ func IsRunning(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrup
126127
time.Sleep(250 * time.Millisecond)
127128
}
128129
log.Errf(c, "Etcd is not answering after %d attempts.", count)
129-
return false, &cookoo.FatalError{"Could not connect to Etcd."}
130+
return false, &cookoo.FatalError{Message: "Could not connect to Etcd."}
130131
}
131132

132133
// Set sets a value in etcd.
@@ -387,12 +388,12 @@ func MakeDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
387388
k := client.NewKeysAPI(cli)
388389

389390
if len(name) == 0 {
390-
return false, errors.New("Expected directory name to be more than zero characters.")
391+
return false, errors.New("expected directory name to be more than zero characters")
391392
}
392393

393394
res, err := k.Set(dctx(), name, "", &client.SetOptions{TTL: ttl, Dir: true})
394395
if err != nil {
395-
return res, &cookoo.RecoverableError{err.Error()}
396+
return res, &cookoo.RecoverableError{Message: err.Error()}
396397
}
397398

398399
return res, nil

etcd/members.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/Masterminds/cookoo"
88
"github.com/Masterminds/cookoo/log"
99
"github.com/coreos/etcd/client"
10-
"k8s.io/apimachinery/pkg/labels"
1110
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/labels"
1212
"k8s.io/client-go/kubernetes"
1313
"k8s.io/client-go/rest"
1414
)
@@ -168,7 +168,7 @@ func RemoveStaleMembers(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo
168168
// Params:
169169
// client (client.Client): An etcd client.
170170
// Returns:
171-
// string representation of the list, also put into the enviornment.
171+
// string representation of the list, also put into the environment.
172172
func GetInitialCluster(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
173173
cli := p.Get("client", nil).(client.Client)
174174
mem := client.NewMembersAPI(cli)

etcd/simple_client.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import (
1111
"github.com/coreos/etcd/client"
1212
)
1313

14-
var (
15-
retryCycles = 2
16-
retrySleep = 200 * time.Millisecond
17-
)
18-
1914
// Getter describes the Get behavior of an Etcd client.
2015
//
2116
// Usually you will want to use go-etcd/etcd.Client to satisfy this.
@@ -53,22 +48,22 @@ type GetterSetter interface {
5348
// - retrySleep (time.Duration): How long to sleep between retries
5449
//
5550
// Returns:
56-
// This puts a simpleEtcdClient into context (implements Getter, Setter, etc.)
51+
// This puts a SimpleEtcdClient into context (implements Getter, Setter, etc.)
5752
func CreateSimpleClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
5853
r, e := CreateClient(c, p)
5954
if e != nil {
6055
return c, e
6156
}
6257

63-
return &simpleEtcdClient{
58+
return &SimpleEtcdClient{
6459
realClient: r.(client.Client),
6560
}, nil
6661
}
6762

68-
// Provides a simple wrapper around the old API.
63+
// NewSimpleClient Provides a simple wrapper around the old API.
6964
//
7065
// DO NOT USE for new code. Instead, use NewClient().
71-
func NewSimpleClient(hosts []string) (*simpleEtcdClient, error) {
66+
func NewSimpleClient(hosts []string) (*SimpleEtcdClient, error) {
7267
cfg := client.Config{
7368
Endpoints: hosts,
7469
}
@@ -78,29 +73,32 @@ func NewSimpleClient(hosts []string) (*simpleEtcdClient, error) {
7873
return nil, err
7974
}
8075

81-
return &simpleEtcdClient{
76+
return &SimpleEtcdClient{
8277
realClient: r,
8378
}, nil
8479
}
8580

86-
// simpleEtcdClient provides an interface compatible with the old Etcd client.
87-
type simpleEtcdClient struct {
81+
// SimpleEtcdClient provides an interface compatible with the old Etcd client.
82+
type SimpleEtcdClient struct {
8883
realClient client.Client
8984
}
9085

91-
func (c *simpleEtcdClient) Get(key string, sort bool, rec bool) (*client.Response, error) {
86+
// Get client.Response
87+
func (c *SimpleEtcdClient) Get(key string, sort bool, rec bool) (*client.Response, error) {
9288
k := client.NewKeysAPI(c.realClient)
9389
return k.Get(dctx(), key, &client.GetOptions{Sort: sort, Recursive: rec})
9490
}
9591

96-
func (c *simpleEtcdClient) Set(key, val string, ttl uint64) (*client.Response, error) {
92+
// Set client.Response
93+
func (c *SimpleEtcdClient) Set(key, val string, ttl uint64) (*client.Response, error) {
9794
k := client.NewKeysAPI(c.realClient)
9895
// We're banking on people not using really uge ttls. In the code base, the
9996
// highest is only a few hundred.
10097
return k.Set(dctx(), key, val, &client.SetOptions{TTL: time.Duration(ttl) * time.Second})
10198
}
10299

103-
func (c *simpleEtcdClient) CreateDir(name string, ttl uint64) (*client.Response, error) {
100+
// CreateDir by name
101+
func (c *SimpleEtcdClient) CreateDir(name string, ttl uint64) (*client.Response, error) {
104102
k := client.NewKeysAPI(c.realClient)
105103
return k.Set(dctx(), name, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true})
106104
}

log/log.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ var (
3232
)
3333

3434
const (
35+
// DebugPrefix for log
3536
DebugPrefix = "[DEBUG]"
37+
38+
// ErrorPrefix for log
3639
ErrorPrefix = "[ERROR]"
37-
WarnPrefix = "[WARN]"
38-
InfoPrefix = "--->"
40+
41+
// WarnPrefix for log
42+
WarnPrefix = "[WARN]"
43+
44+
// InfoPrefix for log
45+
InfoPrefix = "--->"
3946
)
4047

4148
// Logger is the base logging struct from which all logging functionality stems

0 commit comments

Comments
 (0)