Golint fixes
I used: `golint | grep -v comment | grep -v stringer` to avoid crap.
This commit is contained in:
20
config.go
20
config.go
@@ -41,7 +41,7 @@ type edgeConfig struct {
|
||||
To vertexConfig `yaml:"to"`
|
||||
}
|
||||
|
||||
type graphConfig struct {
|
||||
type GraphConfig struct {
|
||||
Graph string `yaml:"graph"`
|
||||
Types struct {
|
||||
Noop []NoopType `yaml:"noop"`
|
||||
@@ -54,7 +54,7 @@ type graphConfig struct {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -64,14 +64,14 @@ func (c *graphConfig) Parse(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseConfigFromFile(filename string) *graphConfig {
|
||||
func ParseConfigFromFile(filename string) *GraphConfig {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Printf("Error: Config: ParseConfigFromFile: File: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
var config graphConfig
|
||||
var config GraphConfig
|
||||
if err := config.Parse(data); err != nil {
|
||||
log.Printf("Error: Config: ParseConfigFromFile: Parse: %v", err)
|
||||
return nil
|
||||
@@ -91,14 +91,14 @@ func ParseConfigFromFile(filename string) *graphConfig {
|
||||
// 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
|
||||
// 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 FileMap map[string]*Vertex = make(map[string]*Vertex)
|
||||
var ServiceMap map[string]*Vertex = make(map[string]*Vertex)
|
||||
var ExecMap map[string]*Vertex = make(map[string]*Vertex)
|
||||
var NoopMap = make(map[string]*Vertex)
|
||||
var FileMap = make(map[string]*Vertex)
|
||||
var ServiceMap = 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["file"] = FileMap
|
||||
lookup["service"] = ServiceMap
|
||||
|
||||
@@ -43,7 +43,7 @@ func ConfigWatch(file string) chan bool {
|
||||
patharray := PathSplit(safename) // tokenize the path
|
||||
var index = len(patharray) // starting index
|
||||
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?
|
||||
|
||||
for {
|
||||
@@ -73,17 +73,17 @@ func ConfigWatch(file string) chan bool {
|
||||
|
||||
select {
|
||||
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,
|
||||
// and the event... doesn't mean we can't watch deeper
|
||||
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) {
|
||||
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) {
|
||||
delta_depth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more
|
||||
deltaDepth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more
|
||||
|
||||
} else {
|
||||
// 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
|
||||
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 event.Name == safename {
|
||||
@@ -100,14 +100,14 @@ func ConfigWatch(file string) chan bool {
|
||||
send = true
|
||||
|
||||
// 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!")
|
||||
watcher.Remove(current)
|
||||
index--
|
||||
}
|
||||
|
||||
// we must be a parent watcher, so descend in
|
||||
if delta_depth < 0 {
|
||||
if deltaDepth < 0 {
|
||||
watcher.Remove(current)
|
||||
index++
|
||||
}
|
||||
@@ -116,13 +116,13 @@ func ConfigWatch(file string) chan bool {
|
||||
} else if HasPathPrefix(safename, event.Name) {
|
||||
//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!")
|
||||
watcher.Remove(current)
|
||||
index--
|
||||
}
|
||||
|
||||
if delta_depth < 0 {
|
||||
if deltaDepth < 0 {
|
||||
log.Println("Parent!")
|
||||
if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir
|
||||
//send = true
|
||||
|
||||
14
etcd.go
14
etcd.go
@@ -54,12 +54,12 @@ type EtcdWObject struct { // etcd wrapper object
|
||||
convergedState etcdConvergedState
|
||||
}
|
||||
|
||||
func (obj *EtcdWObject) GetConvergedState() etcdConvergedState {
|
||||
return obj.convergedState
|
||||
func (etcdO *EtcdWObject) GetConvergedState() etcdConvergedState {
|
||||
return etcdO.convergedState
|
||||
}
|
||||
|
||||
func (obj *EtcdWObject) SetConvergedState(state etcdConvergedState) {
|
||||
obj.convergedState = state
|
||||
func (etcdO *EtcdWObject) SetConvergedState(state etcdConvergedState) {
|
||||
etcdO.convergedState = state
|
||||
}
|
||||
|
||||
func (etcdO *EtcdWObject) GetKAPI() etcd.KeysAPI {
|
||||
@@ -130,8 +130,8 @@ func (etcdO *EtcdWObject) EtcdWatch() chan etcdMsg {
|
||||
etcdch := etcdO.EtcdChannelWatch(watcher, etcd_context.Background())
|
||||
for {
|
||||
log.Printf("Etcd: Watching...")
|
||||
var resp *etcd.Response = nil
|
||||
var err error = nil
|
||||
var resp *etcd.Response // = nil by default
|
||||
var err error
|
||||
select {
|
||||
case out := <-etcdch:
|
||||
etcdO.SetConvergedState(etcdConvergedNil)
|
||||
@@ -252,7 +252,7 @@ func (etcdO *EtcdWObject) EtcdGetProcess(nodes etcd.Nodes, typ string) []string
|
||||
//path := fmt.Sprintf("/exported/%s/types/", h)
|
||||
top := "/exported/"
|
||||
log.Printf("Etcd: Get: %+v", nodes) // Get().Nodes.Nodes
|
||||
output := make([]string, 0)
|
||||
var output []string
|
||||
|
||||
for _, x := range nodes { // loop through hosts
|
||||
if !strings.HasPrefix(x.Key, top) {
|
||||
|
||||
20
file.go
20
file.go
@@ -118,7 +118,7 @@ func (obj *FileType) Watch() {
|
||||
patharray := PathSplit(safename) // tokenize the path
|
||||
var index = len(patharray) // starting index
|
||||
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 exit = 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)
|
||||
}
|
||||
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,
|
||||
// and the event... doesn't mean we can't watch deeper
|
||||
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) {
|
||||
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) {
|
||||
delta_depth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more
|
||||
deltaDepth = len(PathSplit(event.Name)) - len(PathSplit(current)) // +1 or more
|
||||
|
||||
} else {
|
||||
// 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
|
||||
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 event.Name == safename {
|
||||
@@ -188,14 +188,14 @@ func (obj *FileType) Watch() {
|
||||
dirty = true
|
||||
|
||||
// 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!")
|
||||
watcher.Remove(current)
|
||||
index--
|
||||
}
|
||||
|
||||
// we must be a parent watcher, so descend in
|
||||
if delta_depth < 0 {
|
||||
if deltaDepth < 0 {
|
||||
watcher.Remove(current)
|
||||
index++
|
||||
}
|
||||
@@ -204,13 +204,13 @@ func (obj *FileType) Watch() {
|
||||
} else if HasPathPrefix(safename, event.Name) {
|
||||
//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!")
|
||||
watcher.Remove(current)
|
||||
index--
|
||||
}
|
||||
|
||||
if delta_depth < 0 {
|
||||
if deltaDepth < 0 {
|
||||
log.Println("Parent!")
|
||||
if PathPrefixDelta(safename, event.Name) == 1 { // we're the parent dir
|
||||
send = true
|
||||
|
||||
2
main.go
2
main.go
@@ -58,7 +58,7 @@ func waitForSignal(exit chan bool) {
|
||||
}
|
||||
|
||||
func run(c *cli.Context) {
|
||||
var start int64 = time.Now().UnixNano()
|
||||
var start = time.Now().UnixNano()
|
||||
var wg sync.WaitGroup
|
||||
exit := make(chan bool) // exit signal
|
||||
converged := make(chan bool) // converged signal
|
||||
|
||||
37
pgraph.go
37
pgraph.go
@@ -197,7 +197,7 @@ func (g *Graph) NumEdges() int {
|
||||
|
||||
// get an array (slice) of all vertices in the graph
|
||||
func (g *Graph) GetVertices() []*Vertex {
|
||||
vertices := make([]*Vertex, 0)
|
||||
var vertices []*Vertex
|
||||
for k := range g.Adjacency {
|
||||
vertices = append(vertices, k)
|
||||
}
|
||||
@@ -240,9 +240,9 @@ func (g *Graph) Graphviz() (out string) {
|
||||
out += fmt.Sprintf("\tlabel=\"%v\";\n", g.GetName())
|
||||
//out += "\tnode [shape=box];\n"
|
||||
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())
|
||||
for j, _ := range g.Adjacency[i] {
|
||||
for j := range g.Adjacency[i] {
|
||||
k := g.Adjacency[i][j]
|
||||
// use str for clearer output ordering
|
||||
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 {
|
||||
// TODO: we might be able to implement this differently by reversing
|
||||
// the Adjacency graph and then looping through it again...
|
||||
s := make([]*Vertex, 0)
|
||||
for k, _ := range g.Adjacency { // reverse paths
|
||||
for w, _ := range g.Adjacency[k] {
|
||||
var s []*Vertex
|
||||
for k := range g.Adjacency { // reverse paths
|
||||
for w := range g.Adjacency[k] {
|
||||
if w == v {
|
||||
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 -> ???)
|
||||
// poke should use this
|
||||
func (g *Graph) OutgoingGraphEdges(v *Vertex) []*Vertex {
|
||||
s := make([]*Vertex, 0)
|
||||
for k, _ := range g.Adjacency[v] { // forward paths
|
||||
var s []*Vertex
|
||||
for k := range g.Adjacency[v] { // forward paths
|
||||
s = append(s, k)
|
||||
}
|
||||
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
|
||||
func (g *Graph) GraphEdges(v *Vertex) []*Vertex {
|
||||
s := make([]*Vertex, 0)
|
||||
var s []*Vertex
|
||||
s = append(s, g.IncomingGraphEdges(v)...)
|
||||
s = append(s, g.OutgoingGraphEdges(v)...)
|
||||
return s
|
||||
}
|
||||
|
||||
func (g *Graph) DFS(start *Vertex) []*Vertex {
|
||||
d := make([]*Vertex, 0) // discovered
|
||||
s := make([]*Vertex, 0) // stack
|
||||
var d []*Vertex // discovered
|
||||
var s []*Vertex // stack
|
||||
if _, exists := g.Adjacency[start]; !exists {
|
||||
return nil // TODO: error
|
||||
}
|
||||
@@ -393,7 +393,7 @@ func (g *Graph) GetDisconnectedGraphs() chan *Graph {
|
||||
ch := make(chan *Graph)
|
||||
go func() {
|
||||
var start *Vertex
|
||||
d := make([]*Vertex, 0) // discovered
|
||||
var d []*Vertex // discovered
|
||||
c := g.NumVertices()
|
||||
for len(d) < c {
|
||||
|
||||
@@ -433,7 +433,7 @@ func (g *Graph) InDegree() map[*Vertex]int {
|
||||
|
||||
for k := range g.Adjacency {
|
||||
for z := range g.Adjacency[k] {
|
||||
result[z] += 1
|
||||
result[z]++
|
||||
}
|
||||
}
|
||||
return result
|
||||
@@ -447,7 +447,7 @@ func (g *Graph) OutDegree() map[*Vertex]int {
|
||||
for k := range g.Adjacency {
|
||||
result[k] = 0 // initialize
|
||||
for _ = range g.Adjacency[k] {
|
||||
result[k] += 1
|
||||
result[k]++
|
||||
}
|
||||
}
|
||||
return result
|
||||
@@ -458,8 +458,8 @@ func (g *Graph) OutDegree() map[*Vertex]int {
|
||||
// TODO: add memoization, and cache invalidation to speed this up :)
|
||||
func (g *Graph) TopologicalSort() (result []*Vertex, ok bool) { // kahn's algorithm
|
||||
|
||||
L := make([]*Vertex, 0) // empty list that will contain the sorted elements
|
||||
S := make([]*Vertex, 0) // set of all nodes with no incoming edges
|
||||
var L []*Vertex // empty list that will contain the sorted elements
|
||||
var S []*Vertex // set of all nodes with no incoming edges
|
||||
remaining := make(map[*Vertex]int) // amount of edges remaining
|
||||
|
||||
for v, d := range g.InDegree() {
|
||||
@@ -477,7 +477,7 @@ func (g *Graph) TopologicalSort() (result []*Vertex, ok bool) { // kahn's algori
|
||||
v := S[last]
|
||||
S = S[:last]
|
||||
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
|
||||
// remaining, so for 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
|
||||
for c, in := range remaining {
|
||||
if in > 0 {
|
||||
for n, _ := range g.Adjacency[c] {
|
||||
for n := range g.Adjacency[c] {
|
||||
if remaining[n] > 0 {
|
||||
return nil, false // not a dag!
|
||||
}
|
||||
@@ -624,6 +624,7 @@ func HasVertex(v *Vertex, haystack []*Vertex) bool {
|
||||
|
||||
// reverse a list of vertices
|
||||
func Reverse(vs []*Vertex) []*Vertex {
|
||||
//var out []*Vertex // XXX: golint suggests, but it fails testing
|
||||
out := make([]*Vertex, 0) // empty list
|
||||
l := len(vs)
|
||||
for i := range vs {
|
||||
|
||||
@@ -272,8 +272,8 @@ func TestPgraphT8(t *testing.T) {
|
||||
t.Errorf("Should be true instead of false.")
|
||||
}
|
||||
|
||||
v_1 := NewVertex(NewNoopType("v1")) // same value, different objects
|
||||
if HasVertex(v_1, []*Vertex{v1, v2, v3}) != false {
|
||||
v1b := NewVertex(NewNoopType("v1")) // same value, different objects
|
||||
if HasVertex(v1b, []*Vertex{v1, v2, v3}) != false {
|
||||
t.Errorf("Should be false instead of true.")
|
||||
}
|
||||
}
|
||||
|
||||
8
types.go
8
types.go
@@ -152,12 +152,12 @@ func (obj *BaseType) SetState(state typeState) {
|
||||
obj.state = state
|
||||
}
|
||||
|
||||
// get timestamp of a vertex
|
||||
// GetTimestamp returns the timestamp of a vertex
|
||||
func (obj *BaseType) GetTimestamp() int64 {
|
||||
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 {
|
||||
obj.timestamp = time.Now().UnixNano() // update
|
||||
return obj.timestamp
|
||||
@@ -306,8 +306,8 @@ func Process(obj Type) {
|
||||
log.Printf("%v[%v]: Process()", obj.GetType(), obj.GetName())
|
||||
}
|
||||
obj.SetState(typeEvent)
|
||||
var ok bool = true
|
||||
var apply bool = false // did we run an apply?
|
||||
var ok = true
|
||||
var apply = false // did we run an apply?
|
||||
// is it okay to run dependency wise right now?
|
||||
// if not, that's okay because when the dependency runs, it will poke
|
||||
// us back and we will run if needed then!
|
||||
|
||||
Reference in New Issue
Block a user