Golint fixes

I used: `golint | grep -v comment | grep -v stringer` to avoid crap.
This commit is contained in:
James Shubin
2016-01-19 23:18:29 -05:00
parent 4599b393e9
commit 491e9fd9bc
8 changed files with 63 additions and 62 deletions

View File

@@ -41,7 +41,7 @@ type edgeConfig struct {
To vertexConfig `yaml:"to"` To vertexConfig `yaml:"to"`
} }
type graphConfig struct { type GraphConfig struct {
Graph string `yaml:"graph"` Graph string `yaml:"graph"`
Types struct { Types struct {
Noop []NoopType `yaml:"noop"` Noop []NoopType `yaml:"noop"`
@@ -54,7 +54,7 @@ type graphConfig struct {
Comment string `yaml:"comment"` Comment string `yaml:"comment"`
} }
func (c *graphConfig) Parse(data []byte) error { func (c *GraphConfig) Parse(data []byte) error {
if err := yaml.Unmarshal(data, c); err != nil { if err := yaml.Unmarshal(data, c); err != nil {
return err return err
} }
@@ -64,14 +64,14 @@ func (c *graphConfig) Parse(data []byte) error {
return nil return nil
} }
func ParseConfigFromFile(filename string) *graphConfig { func ParseConfigFromFile(filename string) *GraphConfig {
data, err := ioutil.ReadFile(filename) data, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
log.Printf("Error: Config: ParseConfigFromFile: File: %v", err) log.Printf("Error: Config: ParseConfigFromFile: File: %v", err)
return nil return nil
} }
var config graphConfig var config GraphConfig
if err := config.Parse(data); err != nil { if err := config.Parse(data); err != nil {
log.Printf("Error: Config: ParseConfigFromFile: Parse: %v", err) log.Printf("Error: Config: ParseConfigFromFile: Parse: %v", err)
return nil return nil
@@ -91,14 +91,14 @@ func ParseConfigFromFile(filename string) *graphConfig {
// of stuff into etcd, we should probably store the operations to complete in // of stuff into etcd, we should probably store the operations to complete in
// the new graph, and keep retrying until it succeeds, thus blocking any new // the new graph, and keep retrying until it succeeds, thus blocking any new
// etcd operations until that time. // etcd operations until that time.
func UpdateGraphFromConfig(config *graphConfig, hostname string, g *Graph, etcdO *EtcdWObject) bool { func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO *EtcdWObject) bool {
var NoopMap map[string]*Vertex = make(map[string]*Vertex) var NoopMap = make(map[string]*Vertex)
var FileMap map[string]*Vertex = make(map[string]*Vertex) var FileMap = make(map[string]*Vertex)
var ServiceMap map[string]*Vertex = make(map[string]*Vertex) var ServiceMap = make(map[string]*Vertex)
var ExecMap map[string]*Vertex = make(map[string]*Vertex) var ExecMap = make(map[string]*Vertex)
var lookup map[string]map[string]*Vertex = make(map[string]map[string]*Vertex) var lookup = make(map[string]map[string]*Vertex)
lookup["noop"] = NoopMap lookup["noop"] = NoopMap
lookup["file"] = FileMap lookup["file"] = FileMap
lookup["service"] = ServiceMap lookup["service"] = ServiceMap

View File

@@ -43,7 +43,7 @@ func ConfigWatch(file string) chan bool {
patharray := PathSplit(safename) // tokenize the path patharray := PathSplit(safename) // tokenize the path
var index = len(patharray) // starting index var index = len(patharray) // starting index
var current string // current "watcher" location var current string // current "watcher" location
var delta_depth int // depth delta between watcher and event var deltaDepth int // depth delta between watcher and event
var send = false // send event? var send = false // send event?
for { for {
@@ -73,17 +73,17 @@ func ConfigWatch(file string) chan bool {
select { select {
case event := <-watcher.Events: case event := <-watcher.Events:
// the deeper you go, the bigger the delta_depth is... // the deeper you go, the bigger the deltaDepth is...
// this is the difference between what we're watching, // this is the difference between what we're watching,
// and the event... doesn't mean we can't watch deeper // and the event... doesn't mean we can't watch deeper
if current == event.Name { if current == event.Name {
delta_depth = 0 // i was watching what i was looking for deltaDepth = 0 // i was watching what i was looking for
} else if HasPathPrefix(event.Name, current) { } else if HasPathPrefix(event.Name, current) {
delta_depth = len(PathSplit(current)) - len(PathSplit(event.Name)) // -1 or less deltaDepth = len(PathSplit(current)) - len(PathSplit(event.Name)) // -1 or less
} else if HasPathPrefix(current, event.Name) { } else if HasPathPrefix(current, event.Name) {
delta_depth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more deltaDepth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more
} else { } else {
// TODO different watchers get each others events! // TODO different watchers get each others events!
@@ -92,7 +92,7 @@ func ConfigWatch(file string) chan bool {
// event.Name: /tmp/mgmt/f3 and current: /tmp/mgmt/f2 // event.Name: /tmp/mgmt/f3 and current: /tmp/mgmt/f2
continue continue
} }
//log.Printf("The delta depth is: %v", delta_depth) //log.Printf("The delta depth is: %v", deltaDepth)
// if we have what we wanted, awesome, send an event... // if we have what we wanted, awesome, send an event...
if event.Name == safename { if event.Name == safename {
@@ -100,14 +100,14 @@ func ConfigWatch(file string) chan bool {
send = true send = true
// file removed, move the watch upwards // file removed, move the watch upwards
if delta_depth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) { if deltaDepth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) {
//log.Println("Removal!") //log.Println("Removal!")
watcher.Remove(current) watcher.Remove(current)
index-- index--
} }
// we must be a parent watcher, so descend in // we must be a parent watcher, so descend in
if delta_depth < 0 { if deltaDepth < 0 {
watcher.Remove(current) watcher.Remove(current)
index++ index++
} }
@@ -116,13 +116,13 @@ func ConfigWatch(file string) chan bool {
} else if HasPathPrefix(safename, event.Name) { } else if HasPathPrefix(safename, event.Name) {
//log.Println("Above!") //log.Println("Above!")
if delta_depth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) { if deltaDepth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) {
log.Println("Removal!") log.Println("Removal!")
watcher.Remove(current) watcher.Remove(current)
index-- index--
} }
if delta_depth < 0 { if deltaDepth < 0 {
log.Println("Parent!") log.Println("Parent!")
if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir
//send = true //send = true

14
etcd.go
View File

@@ -54,12 +54,12 @@ type EtcdWObject struct { // etcd wrapper object
convergedState etcdConvergedState convergedState etcdConvergedState
} }
func (obj *EtcdWObject) GetConvergedState() etcdConvergedState { func (etcdO *EtcdWObject) GetConvergedState() etcdConvergedState {
return obj.convergedState return etcdO.convergedState
} }
func (obj *EtcdWObject) SetConvergedState(state etcdConvergedState) { func (etcdO *EtcdWObject) SetConvergedState(state etcdConvergedState) {
obj.convergedState = state etcdO.convergedState = state
} }
func (etcdO *EtcdWObject) GetKAPI() etcd.KeysAPI { func (etcdO *EtcdWObject) GetKAPI() etcd.KeysAPI {
@@ -130,8 +130,8 @@ func (etcdO *EtcdWObject) EtcdWatch() chan etcdMsg {
etcdch := etcdO.EtcdChannelWatch(watcher, etcd_context.Background()) etcdch := etcdO.EtcdChannelWatch(watcher, etcd_context.Background())
for { for {
log.Printf("Etcd: Watching...") log.Printf("Etcd: Watching...")
var resp *etcd.Response = nil var resp *etcd.Response // = nil by default
var err error = nil var err error
select { select {
case out := <-etcdch: case out := <-etcdch:
etcdO.SetConvergedState(etcdConvergedNil) etcdO.SetConvergedState(etcdConvergedNil)
@@ -252,7 +252,7 @@ func (etcdO *EtcdWObject) EtcdGetProcess(nodes etcd.Nodes, typ string) []string
//path := fmt.Sprintf("/exported/%s/types/", h) //path := fmt.Sprintf("/exported/%s/types/", h)
top := "/exported/" top := "/exported/"
log.Printf("Etcd: Get: %+v", nodes) // Get().Nodes.Nodes log.Printf("Etcd: Get: %+v", nodes) // Get().Nodes.Nodes
output := make([]string, 0) var output []string
for _, x := range nodes { // loop through hosts for _, x := range nodes { // loop through hosts
if !strings.HasPrefix(x.Key, top) { if !strings.HasPrefix(x.Key, top) {

20
file.go
View File

@@ -118,7 +118,7 @@ func (obj *FileType) Watch() {
patharray := PathSplit(safename) // tokenize the path patharray := PathSplit(safename) // tokenize the path
var index = len(patharray) // starting index var index = len(patharray) // starting index
var current string // current "watcher" location var current string // current "watcher" location
var delta_depth int // depth delta between watcher and event var deltaDepth int // depth delta between watcher and event
var send = false // send event? var send = false // send event?
var exit = false var exit = false
var dirty = false var dirty = false
@@ -159,17 +159,17 @@ func (obj *FileType) Watch() {
log.Printf("File[%v]: Watch(%v), Event(%v): %v", obj.GetName(), current, event.Name, event.Op) log.Printf("File[%v]: Watch(%v), Event(%v): %v", obj.GetName(), current, event.Name, event.Op)
} }
obj.SetConvergedState(typeConvergedNil) // XXX: technically i can detect if the event is erroneous or not first obj.SetConvergedState(typeConvergedNil) // XXX: technically i can detect if the event is erroneous or not first
// the deeper you go, the bigger the delta_depth is... // the deeper you go, the bigger the deltaDepth is...
// this is the difference between what we're watching, // this is the difference between what we're watching,
// and the event... doesn't mean we can't watch deeper // and the event... doesn't mean we can't watch deeper
if current == event.Name { if current == event.Name {
delta_depth = 0 // i was watching what i was looking for deltaDepth = 0 // i was watching what i was looking for
} else if HasPathPrefix(event.Name, current) { } else if HasPathPrefix(event.Name, current) {
delta_depth = len(PathSplit(current)) - len(PathSplit(event.Name)) // -1 or less deltaDepth = len(PathSplit(current)) - len(PathSplit(event.Name)) // -1 or less
} else if HasPathPrefix(current, event.Name) { } else if HasPathPrefix(current, event.Name) {
delta_depth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more deltaDepth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more
} else { } else {
// TODO different watchers get each others events! // TODO different watchers get each others events!
@@ -178,7 +178,7 @@ func (obj *FileType) Watch() {
// event.Name: /tmp/mgmt/f3 and current: /tmp/mgmt/f2 // event.Name: /tmp/mgmt/f3 and current: /tmp/mgmt/f2
continue continue
} }
//log.Printf("The delta depth is: %v", delta_depth) //log.Printf("The delta depth is: %v", deltaDepth)
// if we have what we wanted, awesome, send an event... // if we have what we wanted, awesome, send an event...
if event.Name == safename { if event.Name == safename {
@@ -188,14 +188,14 @@ func (obj *FileType) Watch() {
dirty = true dirty = true
// file removed, move the watch upwards // file removed, move the watch upwards
if delta_depth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) { if deltaDepth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) {
//log.Println("Removal!") //log.Println("Removal!")
watcher.Remove(current) watcher.Remove(current)
index-- index--
} }
// we must be a parent watcher, so descend in // we must be a parent watcher, so descend in
if delta_depth < 0 { if deltaDepth < 0 {
watcher.Remove(current) watcher.Remove(current)
index++ index++
} }
@@ -204,13 +204,13 @@ func (obj *FileType) Watch() {
} else if HasPathPrefix(safename, event.Name) { } else if HasPathPrefix(safename, event.Name) {
//log.Println("Above!") //log.Println("Above!")
if delta_depth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) { if deltaDepth >= 0 && (event.Op&fsnotify.Remove == fsnotify.Remove) {
log.Println("Removal!") log.Println("Removal!")
watcher.Remove(current) watcher.Remove(current)
index-- index--
} }
if delta_depth < 0 { if deltaDepth < 0 {
log.Println("Parent!") log.Println("Parent!")
if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir
send = true send = true

View File

@@ -58,7 +58,7 @@ func waitForSignal(exit chan bool) {
} }
func run(c *cli.Context) { func run(c *cli.Context) {
var start int64 = time.Now().UnixNano() var start = time.Now().UnixNano()
var wg sync.WaitGroup var wg sync.WaitGroup
exit := make(chan bool) // exit signal exit := make(chan bool) // exit signal
converged := make(chan bool) // converged signal converged := make(chan bool) // converged signal

View File

@@ -197,7 +197,7 @@ func (g *Graph) NumEdges() int {
// get an array (slice) of all vertices in the graph // get an array (slice) of all vertices in the graph
func (g *Graph) GetVertices() []*Vertex { func (g *Graph) GetVertices() []*Vertex {
vertices := make([]*Vertex, 0) var vertices []*Vertex
for k := range g.Adjacency { for k := range g.Adjacency {
vertices = append(vertices, k) vertices = append(vertices, k)
} }
@@ -240,9 +240,9 @@ func (g *Graph) Graphviz() (out string) {
out += fmt.Sprintf("\tlabel=\"%v\";\n", g.GetName()) out += fmt.Sprintf("\tlabel=\"%v\";\n", g.GetName())
//out += "\tnode [shape=box];\n" //out += "\tnode [shape=box];\n"
str := "" str := ""
for i, _ := range g.Adjacency { // reverse paths for i := range g.Adjacency { // reverse paths
out += fmt.Sprintf("\t%v [label=\"%v[%v]\"];\n", i.GetName(), i.GetType(), i.GetName()) out += fmt.Sprintf("\t%v [label=\"%v[%v]\"];\n", i.GetName(), i.GetType(), i.GetName())
for j, _ := range g.Adjacency[i] { for j := range g.Adjacency[i] {
k := g.Adjacency[i][j] k := g.Adjacency[i][j]
// use str for clearer output ordering // use str for clearer output ordering
str += fmt.Sprintf("\t%v -> %v [label=%v];\n", i.GetName(), j.GetName(), k.Name) str += fmt.Sprintf("\t%v -> %v [label=%v];\n", i.GetName(), j.GetName(), k.Name)
@@ -318,9 +318,9 @@ func Contains(s []*Vertex, element *Vertex) bool {
func (g *Graph) IncomingGraphEdges(v *Vertex) []*Vertex { func (g *Graph) IncomingGraphEdges(v *Vertex) []*Vertex {
// TODO: we might be able to implement this differently by reversing // TODO: we might be able to implement this differently by reversing
// the Adjacency graph and then looping through it again... // the Adjacency graph and then looping through it again...
s := make([]*Vertex, 0) var s []*Vertex
for k, _ := range g.Adjacency { // reverse paths for k := range g.Adjacency { // reverse paths
for w, _ := range g.Adjacency[k] { for w := range g.Adjacency[k] {
if w == v { if w == v {
s = append(s, k) s = append(s, k)
} }
@@ -332,8 +332,8 @@ func (g *Graph) IncomingGraphEdges(v *Vertex) []*Vertex {
// return an array (slice) of all vertices that vertex v points to (v -> ???) // return an array (slice) of all vertices that vertex v points to (v -> ???)
// poke should use this // poke should use this
func (g *Graph) OutgoingGraphEdges(v *Vertex) []*Vertex { func (g *Graph) OutgoingGraphEdges(v *Vertex) []*Vertex {
s := make([]*Vertex, 0) var s []*Vertex
for k, _ := range g.Adjacency[v] { // forward paths for k := range g.Adjacency[v] { // forward paths
s = append(s, k) s = append(s, k)
} }
return s return s
@@ -341,15 +341,15 @@ func (g *Graph) OutgoingGraphEdges(v *Vertex) []*Vertex {
// return an array (slice) of all vertices that connect to vertex v // return an array (slice) of all vertices that connect to vertex v
func (g *Graph) GraphEdges(v *Vertex) []*Vertex { func (g *Graph) GraphEdges(v *Vertex) []*Vertex {
s := make([]*Vertex, 0) var s []*Vertex
s = append(s, g.IncomingGraphEdges(v)...) s = append(s, g.IncomingGraphEdges(v)...)
s = append(s, g.OutgoingGraphEdges(v)...) s = append(s, g.OutgoingGraphEdges(v)...)
return s return s
} }
func (g *Graph) DFS(start *Vertex) []*Vertex { func (g *Graph) DFS(start *Vertex) []*Vertex {
d := make([]*Vertex, 0) // discovered var d []*Vertex // discovered
s := make([]*Vertex, 0) // stack var s []*Vertex // stack
if _, exists := g.Adjacency[start]; !exists { if _, exists := g.Adjacency[start]; !exists {
return nil // TODO: error return nil // TODO: error
} }
@@ -393,7 +393,7 @@ func (g *Graph) GetDisconnectedGraphs() chan *Graph {
ch := make(chan *Graph) ch := make(chan *Graph)
go func() { go func() {
var start *Vertex var start *Vertex
d := make([]*Vertex, 0) // discovered var d []*Vertex // discovered
c := g.NumVertices() c := g.NumVertices()
for len(d) < c { for len(d) < c {
@@ -433,7 +433,7 @@ func (g *Graph) InDegree() map[*Vertex]int {
for k := range g.Adjacency { for k := range g.Adjacency {
for z := range g.Adjacency[k] { for z := range g.Adjacency[k] {
result[z] += 1 result[z]++
} }
} }
return result return result
@@ -447,7 +447,7 @@ func (g *Graph) OutDegree() map[*Vertex]int {
for k := range g.Adjacency { for k := range g.Adjacency {
result[k] = 0 // initialize result[k] = 0 // initialize
for _ = range g.Adjacency[k] { for _ = range g.Adjacency[k] {
result[k] += 1 result[k]++
} }
} }
return result return result
@@ -458,8 +458,8 @@ func (g *Graph) OutDegree() map[*Vertex]int {
// TODO: add memoization, and cache invalidation to speed this up :) // TODO: add memoization, and cache invalidation to speed this up :)
func (g *Graph) TopologicalSort() (result []*Vertex, ok bool) { // kahn's algorithm func (g *Graph) TopologicalSort() (result []*Vertex, ok bool) { // kahn's algorithm
L := make([]*Vertex, 0) // empty list that will contain the sorted elements var L []*Vertex // empty list that will contain the sorted elements
S := make([]*Vertex, 0) // set of all nodes with no incoming edges var S []*Vertex // set of all nodes with no incoming edges
remaining := make(map[*Vertex]int) // amount of edges remaining remaining := make(map[*Vertex]int) // amount of edges remaining
for v, d := range g.InDegree() { for v, d := range g.InDegree() {
@@ -477,7 +477,7 @@ func (g *Graph) TopologicalSort() (result []*Vertex, ok bool) { // kahn's algori
v := S[last] v := S[last]
S = S[:last] S = S[:last]
L = append(L, v) // add v to tail of L L = append(L, v) // add v to tail of L
for n, _ := range g.Adjacency[v] { for n := range g.Adjacency[v] {
// for each node n remaining in the graph, consume from // for each node n remaining in the graph, consume from
// remaining, so for remaining[n] > 0 // remaining, so for remaining[n] > 0
if remaining[n] > 0 { if remaining[n] > 0 {
@@ -492,7 +492,7 @@ func (g *Graph) TopologicalSort() (result []*Vertex, ok bool) { // kahn's algori
// if graph has edges, eg if any value in rem is > 0 // if graph has edges, eg if any value in rem is > 0
for c, in := range remaining { for c, in := range remaining {
if in > 0 { if in > 0 {
for n, _ := range g.Adjacency[c] { for n := range g.Adjacency[c] {
if remaining[n] > 0 { if remaining[n] > 0 {
return nil, false // not a dag! return nil, false // not a dag!
} }
@@ -624,6 +624,7 @@ func HasVertex(v *Vertex, haystack []*Vertex) bool {
// reverse a list of vertices // reverse a list of vertices
func Reverse(vs []*Vertex) []*Vertex { func Reverse(vs []*Vertex) []*Vertex {
//var out []*Vertex // XXX: golint suggests, but it fails testing
out := make([]*Vertex, 0) // empty list out := make([]*Vertex, 0) // empty list
l := len(vs) l := len(vs)
for i := range vs { for i := range vs {

View File

@@ -272,8 +272,8 @@ func TestPgraphT8(t *testing.T) {
t.Errorf("Should be true instead of false.") t.Errorf("Should be true instead of false.")
} }
v_1 := NewVertex(NewNoopType("v1")) // same value, different objects v1b := NewVertex(NewNoopType("v1")) // same value, different objects
if HasVertex(v_1, []*Vertex{v1, v2, v3}) != false { if HasVertex(v1b, []*Vertex{v1, v2, v3}) != false {
t.Errorf("Should be false instead of true.") t.Errorf("Should be false instead of true.")
} }
} }

View File

@@ -152,12 +152,12 @@ func (obj *BaseType) SetState(state typeState) {
obj.state = state obj.state = state
} }
// get timestamp of a vertex // GetTimestamp returns the timestamp of a vertex
func (obj *BaseType) GetTimestamp() int64 { func (obj *BaseType) GetTimestamp() int64 {
return obj.timestamp return obj.timestamp
} }
// update timestamp of a vertex // UpdateTimestamp updates the timestamp on a vertex and returns the new value
func (obj *BaseType) UpdateTimestamp() int64 { func (obj *BaseType) UpdateTimestamp() int64 {
obj.timestamp = time.Now().UnixNano() // update obj.timestamp = time.Now().UnixNano() // update
return obj.timestamp return obj.timestamp
@@ -306,8 +306,8 @@ func Process(obj Type) {
log.Printf("%v[%v]: Process()", obj.GetType(), obj.GetName()) log.Printf("%v[%v]: Process()", obj.GetType(), obj.GetName())
} }
obj.SetState(typeEvent) obj.SetState(typeEvent)
var ok bool = true var ok = true
var apply bool = false // did we run an apply? var apply = false // did we run an apply?
// is it okay to run dependency wise right now? // is it okay to run dependency wise right now?
// if not, that's okay because when the dependency runs, it will poke // if not, that's okay because when the dependency runs, it will poke
// us back and we will run if needed then! // us back and we will run if needed then!