Permalink
Browse files

Improve the code style with the help of Go lint

  • Loading branch information...
1 parent dda12ce commit 3ca0fc27e0945a60bb6e09a6900b5123e8ea6131 @etix committed Jun 17, 2017
View
@@ -42,8 +42,8 @@ const (
var (
log = logging.MustGetLogger("main")
- // NoSyncMethod is returned when no sync protocol is available
- NoSyncMethod = errors.New("no suitable URL for the scan")
+ // ErrNoSyncMethod is returned when no sync protocol is available
+ ErrNoSyncMethod = errors.New("no suitable URL for the scan")
)
type cli struct{}
@@ -572,7 +572,7 @@ func (c *cli) CmdScan(args ...string) error {
}
}()
- err = NoSyncMethod
+ err = ErrNoSyncMethod
if *rsync == true || *ftp == true {
// Use the requested protocol
View
@@ -52,6 +52,7 @@ var (
subscribersLock sync.RWMutex
)
+// Configuration contains all the option available in the yaml file
type Configuration struct {
Repository string `yaml:"Repository"`
Templates string `yaml:"Templates"`
@@ -82,7 +83,7 @@ type Configuration struct {
}
type fallback struct {
- Url string `yaml:"URL"`
+ URL string `yaml:"URL"`
CountryCode string `yaml:"CountryCode"`
ContinentCode string `yaml:"ContinentCode"`
}
@@ -188,6 +189,8 @@ func SetConfiguration(c *Configuration) {
config = c
}
+// SubscribeConfig allows subscribers to get notified when
+// the configuration is updated.
func SubscribeConfig(subscriber chan bool) {
subscribersLock.Lock()
defer subscribersLock.Unlock()
View
@@ -3,6 +3,7 @@
package core
+// Banner is a piece of (ascii) art shown during startup
var Banner = ` _______ __ __ __ __
| | |__|.----.----.-----.----.| |--.|__| |_.-----.
| | || _| _| _ | _|| _ || | _|__ --|
View
@@ -0,0 +1,14 @@
+// Copyright (c) 2014-2017 Ludovic Fauvet
+// Licensed under the MIT license
+
+package core
+
+// ContextKey reprensents a context key associated with a value
+type ContextKey int
+
+const (
+ // ContextAllowRedirects is the key for option: AllowRedirects
+ ContextAllowRedirects ContextKey = iota
+ // ContextMirrorID is the key for the variable: MirrorID
+ ContextMirrorID
+)
View
@@ -28,6 +28,7 @@ func init() {
flag.Parse()
}
+// Args returns the list of arguments passed to the command line
func Args() []string {
return flag.Args()
}
View
@@ -24,7 +24,7 @@ type cluster struct {
redis *database.Redis
nodeID string
- nodes []Node
+ nodes []node
nodeIndex int
nodeTotal int
nodesLock sync.RWMutex
@@ -35,21 +35,22 @@ type cluster struct {
StartStopLock sync.Mutex
}
-type Node struct {
+type node struct {
ID string
LastAnnounce int64
}
-type ByNodeID []Node
+type byNodeID []node
-func (n ByNodeID) Len() int { return len(n) }
-func (n ByNodeID) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
-func (n ByNodeID) Less(i, j int) bool { return n[i].ID < n[j].ID }
+func (n byNodeID) Len() int { return len(n) }
+func (n byNodeID) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
+func (n byNodeID) Less(i, j int) bool { return n[i].ID < n[j].ID }
+// NewCluster creates a new instance of the cluster agent
func NewCluster(r *database.Redis) *cluster {
c := &cluster{
redis: r,
- nodes: make([]Node, 0),
+ nodes: make([]node, 0),
stop: make(chan bool),
}
@@ -142,14 +143,14 @@ func (c *cluster) refreshNodeList(nodeID, self string) {
if nodeID != self {
log.Noticef("-> Node %s joined the cluster", nodeID)
}
- n := Node{
+ n := node{
ID: nodeID,
LastAnnounce: time.Now().UTC().Unix(),
}
// TODO use binary search here
// See https://golang.org/pkg/sort/#Search
c.nodes = append(c.nodes, n)
- sort.Sort(ByNodeID(c.nodes))
+ sort.Sort(byNodeID(c.nodes))
}
c.nodeTotal = len(c.nodes)
View
@@ -47,7 +47,7 @@ func TestClusterLoop(t *testing.T) {
c := NewCluster(conn)
- cmd_publish := mock.Command("PUBLISH", string(database.CLUSTER), fmt.Sprintf("%s %s", clusterAnnounce, c.nodeID)).Expect("1")
+ cmdPublish := mock.Command("PUBLISH", string(database.CLUSTER), fmt.Sprintf("%s %s", clusterAnnounce, c.nodeID)).Expect("1")
c.Start()
defer c.Stop()
@@ -58,7 +58,7 @@ func TestClusterLoop(t *testing.T) {
if time.Since(n) > 1500*time.Millisecond {
t.Fatalf("Announce not made")
}
- if mock.Stats(cmd_publish) > 0 {
+ if mock.Stats(cmdPublish) > 0 {
// Success
break
}
@@ -72,19 +72,19 @@ func TestRefreshNodeList(t *testing.T) {
c := NewCluster(conn)
- n := Node{
+ n := node{
ID: "test-4242",
LastAnnounce: time.Now().UTC().Unix(),
}
c.nodes = append(c.nodes, n)
- sort.Sort(ByNodeID(c.nodes))
+ sort.Sort(byNodeID(c.nodes))
- n = Node{
+ n = node{
ID: "meh-4242",
LastAnnounce: time.Now().UTC().Add(time.Second * -6).Unix(),
}
c.nodes = append(c.nodes, n)
- sort.Sort(ByNodeID(c.nodes))
+ sort.Sort(byNodeID(c.nodes))
c.Start()
defer c.Stop()
@@ -199,16 +199,16 @@ func TestIsHandled(t *testing.T) {
handled := 0
if c.IsHandled("aaa") {
- handled += 1
+ handled++
}
if c.IsHandled("bbb") {
- handled += 1
+ handled++
}
if c.IsHandled("ccc") {
- handled += 1
+ handled++
}
if c.IsHandled("ddd") {
- handled += 1
+ handled++
}
if handled != 2 {
Oops, something went wrong.

0 comments on commit 3ca0fc2

Please sign in to comment.