Skip to content

Commit

Permalink
change log and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gilsegment committed Jun 17, 2021
1 parent 49507bf commit ade0443
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tableize.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Input struct {
// Optional
HintSize int
Substitutions map[string]string
StringifyArr bool
StringifyArrays bool
}

// Tableize the given map by flattening and normalizing all
Expand All @@ -26,7 +26,7 @@ func Tableize(in *Input) map[string]interface{} {
}

ret := make(map[string]interface{}, in.HintSize)
visit(ret, in.Value, "", in.Substitutions, in.StringifyArr)
visit(ret, in.Value, "", in.Substitutions, in.StringifyArrays)
return ret
}

Expand Down Expand Up @@ -57,7 +57,7 @@ func visit(ret map[string]interface{}, m map[string]interface{}, prefix string,
if stringifyArr {
valByteArr, err := json.Marshal(val)
if err != nil {
log.Printf("[Error] Unable to marshall value `%v` err: %v", val, err)
log.Printf("go-tableize: dropping array value %+v that could not be converted to string: %s\n", val, err)
} else {
ret[key] = string(valByteArr)
}
Expand Down
6 changes: 3 additions & 3 deletions tableize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestTableizeArray(t *testing.T) {
}{
{
desc: "array inside big JSON",
input: Input{Value: prop, StringifyArr: true},
input: Input{Value: prop, StringifyArrays: true},
expected: map[string]interface{}{
"context_latitude": nil,
"context_location": nil,
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestTableizeArray(t *testing.T) {
desc: "simple arr StringifyArr=true",
input: Input{Value: map[string]interface{}{
"colors": []interface{}{"red", "blue"},
}, StringifyArr: true,
}, StringifyArrays: true,
},
expected: map[string]interface{}{
"colors": "[\"red\",\"blue\"]",
Expand All @@ -166,7 +166,7 @@ func TestTableizeArray(t *testing.T) {
desc: "simple arr StringifyArr=false",
input: Input{Value: map[string]interface{}{
"colors": []interface{}{"red", "blue"},
}, StringifyArr: false,
}, StringifyArrays: false,
},
expected: map[string]interface{}{
"colors": []interface{}{"red", "blue"},
Expand Down

0 comments on commit ade0443

Please sign in to comment.