Skip to content

Commit 96a4931

Browse files
committed
various formatting and other fixes
1 parent 62a55b6 commit 96a4931

17 files changed

Lines changed: 330 additions & 326 deletions

.circleci/config.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,24 @@ jobs:
2323
keys:
2424
- v1-go-src-{{ .Branch }}-{{ .Revision }}
2525
- run:
26-
name: Install gometalinter
27-
command: |
28-
go get -u github.com/alecthomas/gometalinter
29-
gometalinter --install
26+
name: Get shadow
27+
command: go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
28+
- run:
29+
name: Install shadow
30+
command: go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
31+
- run:
32+
name: Download and install errcheck
33+
command: go get -u github.com/kisielk/errcheck
34+
- run:
35+
name: Download and install misspell
36+
command: go get -u github.com/client9/misspell/cmd/misspell
37+
- run:
38+
name: Download and install ineffassign
39+
command: go get -u github.com/gordonklaus/ineffassign
3040
- run:
31-
name: Test
32-
command: bash scripts/test.sh
41+
name: Download and install staticheck
42+
command: go get -u honnef.co/go/tools/cmd/staticcheck
43+
- run: bash scripts/test.sh
3344
validate:
3445
executor: base
3546
steps:

gss/DeserializeBytes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ func unescapePropertyText(in string) string {
2929
return out
3030
}
3131

32-
func deserializeBSON(input_bytes []byte, outputType reflect.Type) (interface{}, error) {
32+
func deserializeBSON(inputBytes []byte, outputType reflect.Type) (interface{}, error) {
3333
if outputType.Kind() == reflect.Map {
3434
ptr := reflect.New(outputType)
3535
ptr.Elem().Set(reflect.MakeMap(outputType))
36-
err := bson.Unmarshal(input_bytes, ptr.Interface())
36+
err := bson.Unmarshal(inputBytes, ptr.Interface())
3737
if err != nil {
3838
return nil, errors.Wrap(err, "error unmarshalling bytes into BSON")
3939
}
4040
return ptr.Elem().Interface(), nil
4141
} else if outputType.Kind() == reflect.Slice {
4242
ptr := reflect.New(outputType)
4343
ptr.Elem().Set(reflect.MakeSlice(outputType, 0, 0))
44-
err := bson.Unmarshal(input_bytes, ptr.Interface())
44+
err := bson.Unmarshal(inputBytes, ptr.Interface())
4545
if err != nil {
4646
return nil, errors.Wrap(err, "error unmarshalling bytes into BSON")
4747
}
@@ -55,7 +55,7 @@ func DeserializeBytes(input *DeserializeInput) (interface{}, error) {
5555

5656
switch input.Format {
5757
case "csv", "tsv":
58-
return DeserializeCSV(bytes.NewReader(input.Bytes), input.Format, input.Header, input.Comment, input.LazyQuotes, input.SkipLines, input.Limit, input.Type)
58+
return DeserializeSV(bytes.NewReader(input.Bytes), input.Format, input.Header, input.Comment, input.LazyQuotes, input.SkipLines, input.Limit, input.Type)
5959
case "properties":
6060
return DeserializeProperties(string(input.Bytes), input.Comment, input.Type)
6161
case "bson":

gss/DeserializeJSON.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ import (
1616

1717
// DeserializeJSON deserializes the input bytes into a Go object.
1818
// - https://golang.org/pkg/encoding/json/
19-
func DeserializeJSON(input_bytes []byte, output_type reflect.Type) (interface{}, error) {
20-
if output_type.Kind() == reflect.Map {
21-
ptr := reflect.New(output_type)
22-
ptr.Elem().Set(reflect.MakeMap(output_type))
23-
err := json.Unmarshal(input_bytes, ptr.Interface())
19+
func DeserializeJSON(inputBytes []byte, outputType reflect.Type) (interface{}, error) {
20+
if outputType.Kind() == reflect.Map {
21+
ptr := reflect.New(outputType)
22+
ptr.Elem().Set(reflect.MakeMap(outputType))
23+
err := json.Unmarshal(inputBytes, ptr.Interface())
2424
if err != nil {
2525
return nil, errors.Wrap(err, "error unmarshalling bytes into JSON")
2626
}
2727
return ptr.Elem().Interface(), nil
28-
} else if output_type.Kind() == reflect.Slice {
29-
ptr := reflect.New(output_type)
30-
ptr.Elem().Set(reflect.MakeSlice(output_type, 0, 0))
31-
err := json.Unmarshal(input_bytes, ptr.Interface())
28+
} else if outputType.Kind() == reflect.Slice {
29+
ptr := reflect.New(outputType)
30+
ptr.Elem().Set(reflect.MakeSlice(outputType, 0, 0))
31+
err := json.Unmarshal(inputBytes, ptr.Interface())
3232
if err != nil {
3333
return nil, errors.Wrap(err, "error unmarshalling bytes into JSON")
3434
}
3535
return ptr.Elem().Interface(), nil
3636
}
37-
return nil, errors.New("Invalid output type for json " + fmt.Sprint(output_type))
37+
return nil, errors.New("Invalid output type for json " + fmt.Sprint(outputType))
3838
}

gss/DeserializeProperties.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ import (
1717

1818
// DeserializeProperties deserializes a properties string into a Go instance.
1919
// - https://en.wikipedia.org/wiki/.properties
20-
func DeserializeProperties(input string, input_comment string, output_type reflect.Type) (interface{}, error) {
21-
m := reflect.MakeMap(output_type)
22-
if len(input_comment) == 0 {
23-
input_comment = "#"
20+
func DeserializeProperties(input string, inputComment string, outputType reflect.Type) (interface{}, error) {
21+
m := reflect.MakeMap(outputType)
22+
if len(inputComment) == 0 {
23+
inputComment = "#"
2424
}
2525
scanner := bufio.NewScanner(strings.NewReader(input))
2626
scanner.Split(bufio.ScanLines)
2727
property := ""
2828
for scanner.Scan() {
2929
line := scanner.Text()
30-
if len(line) > 0 && !strings.HasPrefix(line, input_comment) {
30+
if len(line) > 0 && !strings.HasPrefix(line, inputComment) {
3131
if line[len(line)-1] == '\\' {
3232
property += strings.TrimLeftFunc(line[0:len(line)-1], unicode.IsSpace)
3333
} else {
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import (
1414
"reflect"
1515
)
1616

17-
// DeserializeCSV deserializes a CSV or TSV string into a Go instance.
17+
// DeserializeSV deserializes a CSV or TSV string into a Go instance.
1818
// - https://golang.org/pkg/encoding/csv/
19-
func DeserializeCSV(input io.Reader, format string, input_header []string, input_comment string, inputLazyQuotes bool, inputSkipLines int, inputLimit int, output_type reflect.Type) (interface{}, error) {
19+
func DeserializeSV(input io.Reader, format string, inputHeader []string, inputComment string, inputLazyQuotes bool, inputSkipLines int, inputLimit int, outputType reflect.Type) (interface{}, error) {
2020

21-
if output_type.Kind() == reflect.Map {
21+
if outputType.Kind() == reflect.Map {
2222
if inputLimit != 1 {
23-
return nil, errors.Wrap(&ErrInvalidLimit{Value: inputLimit}, "DeserializeCSV expects input limit of 1 when output type is of kind map.")
23+
return nil, errors.Wrap(&ErrInvalidLimit{Value: inputLimit}, "DeserializeSV expects input limit of 1 when output type is of kind map.")
2424
}
25-
if len(input_header) == 0 {
26-
return nil, errors.New("deserializeCSV when returning a map type expects a input header")
25+
if len(inputHeader) == 0 {
26+
return nil, errors.New("deserializeSV when returning a map type expects a input header")
2727
}
28-
} else if !(output_type.Kind() == reflect.Array || output_type.Kind() == reflect.Slice) {
29-
return nil, &ErrInvalidKind{Value: output_type.Kind(), Valid: []reflect.Kind{reflect.Array, reflect.Slice, reflect.Map}}
28+
} else if !(outputType.Kind() == reflect.Array || outputType.Kind() == reflect.Slice) {
29+
return nil, &ErrInvalidKind{Value: outputType.Kind(), Valid: []reflect.Kind{reflect.Array, reflect.Slice, reflect.Map}}
3030
}
3131

3232
reader := csv.NewReader(input)
@@ -36,13 +36,13 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
3636
reader.LazyQuotes = inputLazyQuotes
3737
reader.FieldsPerRecord = -1 // records may have a variable number of fields
3838

39-
if len(input_comment) > 1 {
39+
if len(inputComment) > 1 {
4040
return nil, errors.New("go's encoding/csv package only supports single character comment characters")
41-
} else if len(input_comment) == 1 {
42-
reader.Comment = []rune(input_comment)[0]
41+
} else if len(inputComment) == 1 {
42+
reader.Comment = []rune(inputComment)[0]
4343
}
4444

45-
if output_type.Kind() == reflect.Map {
45+
if outputType.Kind() == reflect.Map {
4646
inRow, err := reader.Read()
4747
if err != nil {
4848
if err == io.EOF {
@@ -53,8 +53,8 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
5353
if len(inRow) == 0 {
5454
return nil, &ErrEmptyRow{}
5555
}
56-
m := reflect.MakeMap(output_type)
57-
for i, h := range input_header {
56+
m := reflect.MakeMap(outputType)
57+
for i, h := range inputHeader {
5858
// if the number of columns in the header is greater than in the row,
5959
// then break and return data for the columns that are there
6060
if i >= len(inRow) {
@@ -65,17 +65,17 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
6565
return m.Interface(), nil
6666
}
6767

68-
if len(input_header) == 0 {
68+
if len(inputHeader) == 0 {
6969
h, err := reader.Read()
7070
if err != nil {
7171
if err != io.EOF {
7272
return nil, errors.Wrap(err, "Error reading header from input with format csv")
7373
}
7474
}
75-
input_header = h
75+
inputHeader = h
7676
}
7777

78-
output := reflect.MakeSlice(output_type, 0, 0)
78+
output := reflect.MakeSlice(outputType, 0, 0)
7979
for {
8080
inRow, err := reader.Read()
8181
if err != nil {
@@ -85,8 +85,8 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
8585
return nil, errors.Wrap(err, "error reading row into slice from input with format csv")
8686
}
8787
}
88-
m := reflect.MakeMap(output_type.Elem())
89-
for i, h := range input_header {
88+
m := reflect.MakeMap(outputType.Elem())
89+
for i, h := range inputHeader {
9090
if i < len(inRow) {
9191
m.SetMapIndex(reflect.ValueOf(h), reflect.ValueOf(inRow[i]))
9292
}

gss/DeserializeTOML.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616

1717
// DeserializeTOML deserializes an input TOML string into a Go object
1818
// - https://godoc.org/pkg/github.com/BurntSushi/toml
19-
func DeserializeTOML(input string, output_type reflect.Type) (interface{}, error) {
20-
if output_type.Kind() == reflect.Map {
21-
ptr := reflect.New(output_type)
22-
ptr.Elem().Set(reflect.MakeMap(output_type))
19+
func DeserializeTOML(input string, outputType reflect.Type) (interface{}, error) {
20+
if outputType.Kind() == reflect.Map {
21+
ptr := reflect.New(outputType)
22+
ptr.Elem().Set(reflect.MakeMap(outputType))
2323
_, err := toml.Decode(input, ptr.Interface())
2424
return ptr.Elem().Interface(), err
2525
}
26-
return nil, errors.New("Invalid output type for toml " + fmt.Sprint(output_type))
26+
return nil, errors.New("Invalid output type for toml " + fmt.Sprint(outputType))
2727
}

gss/DeserializeYAML.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ package gss
99

1010
import (
1111
"fmt"
12+
"reflect"
13+
)
14+
15+
import (
1216
"github.com/pkg/errors"
1317
"gopkg.in/yaml.v2"
14-
"reflect"
18+
)
19+
20+
import (
21+
stringify "github.com/spatialcurrent/go-stringify"
1522
)
1623

1724
// DeserializeYAML deserializes the YAML input bytes into a Go object
18-
func DeserializeYAML(input_bytes []byte, output_type reflect.Type) (interface{}, error) {
19-
if output_type.Kind() == reflect.Map {
20-
ptr := reflect.New(output_type)
21-
ptr.Elem().Set(reflect.MakeMap(output_type))
22-
err := yaml.Unmarshal(input_bytes, ptr.Interface())
25+
func DeserializeYAML(inputBytes []byte, outputType reflect.Type) (interface{}, error) {
26+
if outputType.Kind() == reflect.Map {
27+
ptr := reflect.New(outputType)
28+
ptr.Elem().Set(reflect.MakeMap(outputType))
29+
err := yaml.Unmarshal(inputBytes, ptr.Interface())
2330
return ptr.Elem().Interface(), err
24-
} else if output_type.Kind() == reflect.Slice {
25-
ptr := reflect.New(output_type)
26-
ptr.Elem().Set(reflect.MakeSlice(output_type, 0, 0))
27-
err := yaml.Unmarshal(input_bytes, ptr.Interface())
28-
return StringifyMapKeys(ptr.Elem().Interface()), err
31+
} else if outputType.Kind() == reflect.Slice {
32+
ptr := reflect.New(outputType)
33+
ptr.Elem().Set(reflect.MakeSlice(outputType, 0, 0))
34+
err := yaml.Unmarshal(inputBytes, ptr.Interface())
35+
return stringify.StringifyMapKeys(ptr.Elem().Interface()), err
2936
}
30-
return nil, errors.New("Invalid output type for yaml " + fmt.Sprint(output_type))
37+
return nil, errors.New("Invalid output type for yaml " + fmt.Sprint(outputType))
3138
}

0 commit comments

Comments
 (0)