Skip to content

Commit 113e080

Browse files
committed
Use camel case in favour of underscored names
1 parent 1029ba1 commit 113e080

File tree

7 files changed

+52
-52
lines changed

7 files changed

+52
-52
lines changed

formatter/dot.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func formatDot(in interface{}) (out string) {
4747
return fmt.Sprintf("graph{\n%s}", buf.String())
4848
}
4949

50-
func flatten(in interface{}, current_path string) ([]node, []link) {
50+
func flatten(in interface{}, currentPath string) ([]node, []link) {
5151
var nodes []node
5252
var links []link
5353

@@ -62,62 +62,62 @@ func flatten(in interface{}, current_path string) ([]node, []link) {
6262
vv := in.(map[string]interface{})
6363

6464
for key, value := range vv {
65-
target := current_path + "-" + key
65+
target := currentPath + "-" + key
6666

6767
nodes = append(nodes, node{
6868
name: target,
6969
label: key,
7070
})
7171

72-
if current_path != "" {
72+
if currentPath != "" {
7373
links = append(links, link{
74-
left: current_path,
74+
left: currentPath,
7575
right: target,
7676
})
7777
}
7878

79-
new_nodes, new_links := flatten(value, target)
79+
newNodes, newLinks := flatten(value, target)
8080

81-
nodes = append(nodes, new_nodes...)
82-
links = append(links, new_links...)
81+
nodes = append(nodes, newNodes...)
82+
links = append(links, newLinks...)
8383
}
8484

8585
return nodes, links
8686
case reflect.Array, reflect.Slice:
8787
for index := 0; index < val.Len(); index++ {
8888
value := val.Index(index).Interface()
8989

90-
target := current_path + "-" + fmt.Sprint(index)
90+
target := currentPath + "-" + fmt.Sprint(index)
9191

9292
nodes = append(nodes, node{
9393
name: target,
9494
label: fmt.Sprintf("[%d]", index),
9595
})
9696

97-
if current_path != "" {
97+
if currentPath != "" {
9898
links = append(links, link{
99-
left: current_path,
99+
left: currentPath,
100100
right: target,
101101
})
102102
}
103103

104-
new_nodes, new_links := flatten(value, target)
104+
newNodes, newLinks := flatten(value, target)
105105

106-
nodes = append(nodes, new_nodes...)
107-
links = append(links, new_links...)
106+
nodes = append(nodes, newNodes...)
107+
links = append(links, newLinks...)
108108
}
109109

110110
return nodes, links
111111
default:
112-
target := current_path + "=content"
112+
target := currentPath + "=content"
113113

114114
nodes = append(nodes, node{
115115
name: target,
116116
label: fmt.Sprint(in),
117117
})
118118

119119
links = append(links, link{
120-
left: current_path,
120+
left: currentPath,
121121
right: target,
122122
})
123123

formatter/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
)
88

99
func formatJson(in interface{}) (out string) {
10-
in_map, ok := in.(map[string]interface{})
10+
inMap, ok := in.(map[string]interface{})
1111

1212
if !ok {
1313
return fmt.Sprintf("\"%s\"", in)
1414
}
1515

16-
m := mxj.Map(in_map)
16+
m := mxj.Map(inMap)
1717

1818
bytes, err := m.JsonIndent("", " ")
1919

formatter/util.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ func forceStringKeys(in interface{}) interface{} {
1010

1111
switch val.Kind() {
1212
case reflect.Map:
13-
new_map := make(map[string]interface{}, val.Len())
13+
newMap := make(map[string]interface{}, val.Len())
1414

1515
for _, key := range val.MapKeys() {
16-
string_key := fmt.Sprint(key.Interface())
17-
new_map[string_key] = forceStringKeys(val.MapIndex(key).Interface())
16+
stringKey := fmt.Sprint(key.Interface())
17+
newMap[stringKey] = forceStringKeys(val.MapIndex(key).Interface())
1818
}
1919

20-
return new_map
20+
return newMap
2121
case reflect.Array, reflect.Slice:
22-
new_slice := make([]interface{}, val.Len())
22+
newSlice := make([]interface{}, val.Len())
2323

2424
for i := 0; i < val.Len(); i++ {
2525
value := val.Index(i).Interface()
26-
new_slice[i] = forceStringKeys(value)
26+
newSlice[i] = forceStringKeys(value)
2727
}
2828

29-
return new_slice
29+
return newSlice
3030
default:
3131
return in
3232
}

parse.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func parseHelp() {
3232

3333
func parseCommand(args []string) {
3434
// Flags
35-
in_format := getopt.String('i', "auto")
36-
out_format := getopt.String('o', "bash")
35+
inFormat := getopt.String('i', "auto")
36+
outFormat := getopt.String('o', "bash")
3737

3838
opts := getopt.CommandLine
3939

@@ -56,7 +56,7 @@ func parseCommand(args []string) {
5656
}
5757

5858
// Try parsing
59-
parsed, err := parser.Parse(input, *in_format)
59+
parsed, err := parser.Parse(input, *inFormat)
6060

6161
if err != nil {
6262
fmt.Fprintln(os.Stderr, err)
@@ -74,7 +74,7 @@ func parseCommand(args []string) {
7474
}
7575

7676
// ...and format back out :)
77-
output, err := formatter.Format(parsed, *out_format)
77+
output, err := formatter.Format(parsed, *outFormat)
7878

7979
if err != nil {
8080
fmt.Fprintln(os.Stderr, err)

parser/filter.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@ func Filter(in interface{}, path string) (interface{}, error) {
1414
return in, nil
1515
}
1616

17-
split_path := strings.SplitN(path, ".", 2)
17+
splitPath := strings.SplitN(path, ".", 2)
1818

19-
this_path := split_path[0]
20-
var next_path string
19+
thisPath := splitPath[0]
20+
var nextPath string
2121

22-
if len(split_path) > 1 {
23-
next_path = split_path[1]
22+
if len(splitPath) > 1 {
23+
nextPath = splitPath[1]
2424
}
2525

2626
val := reflect.ValueOf(in)
2727

2828
switch val.Kind() {
2929
case reflect.Map:
3030
for _, key := range val.MapKeys() {
31-
if fmt.Sprint(key.Interface()) == this_path {
31+
if fmt.Sprint(key.Interface()) == thisPath {
3232
value := val.MapIndex(key).Interface()
33-
return Filter(value, next_path)
33+
return Filter(value, nextPath)
3434
}
3535
}
3636

3737
break
3838
case reflect.Array, reflect.Slice:
39-
index, err := strconv.Atoi(this_path)
39+
index, err := strconv.Atoi(thisPath)
4040

4141
if err != nil || index < 0 || index >= val.Len() {
4242
break
4343
}
4444

45-
return Filter(val.Index(index).Interface(), next_path)
45+
return Filter(val.Index(index).Interface(), nextPath)
4646
}
4747

48-
return nil, fmt.Errorf("Key does not exist: %s", this_path)
48+
return nil, fmt.Errorf("Key does not exist: %s", thisPath)
4949
}

parser/html.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ func formatHtml(n *html.Node) map[string]interface{} {
4141
out["#text"] = c.Data
4242
}
4343
} else {
44-
existing_value, exists := out[c.Data]
44+
existingValue, exists := out[c.Data]
4545

46-
new_value := formatHtml(c)
46+
newValue := formatHtml(c)
4747

4848
if !exists {
49-
out[c.Data] = new_value
49+
out[c.Data] = newValue
5050
} else {
51-
val := reflect.ValueOf(existing_value)
51+
val := reflect.ValueOf(existingValue)
5252

5353
kind := val.Kind()
5454

5555
if kind != reflect.Array && kind != reflect.Slice {
5656
out[c.Data] = []interface{}{
57-
existing_value,
58-
new_value,
57+
existingValue,
58+
newValue,
5959
}
6060
} else {
6161
// *this* is sick
62-
out[c.Data] = reflect.Append(val, reflect.ValueOf(new_value)).Interface().([]interface{})
62+
out[c.Data] = reflect.Append(val, reflect.ValueOf(newValue)).Interface().([]interface{})
6363
}
6464
}
6565
}

parser/mime.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ import (
88
)
99

1010
func parseMime(input []byte) (interface{}, error) {
11-
input_reader := bufio.NewReader(bytes.NewReader(input))
11+
inputReader := bufio.NewReader(bytes.NewReader(input))
1212

13-
reader := textproto.NewReader(input_reader)
13+
reader := textproto.NewReader(inputReader)
1414

1515
headers, err := reader.ReadMIMEHeader()
1616
if err != nil {
1717
return nil, err
1818
}
1919

20-
bytes_body, err := ioutil.ReadAll(input_reader)
20+
bytesBody, err := ioutil.ReadAll(inputReader)
2121
if err != nil {
2222
return nil, err
2323
}
2424

25-
message_headers := make(map[string]interface{})
25+
messageHeaders := make(map[string]interface{})
2626
for key, value := range headers {
27-
message_headers[key] = value
27+
messageHeaders[key] = value
2828
}
2929

3030
message := make(map[string]interface{})
31-
message["headers"] = message_headers
32-
message["body"] = string(bytes_body)
31+
message["headers"] = messageHeaders
32+
message["body"] = string(bytesBody)
3333

3434
return message, nil
3535
}

0 commit comments

Comments
 (0)