Skip to content

Commit

Permalink
Fix gofmt and golint issues (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
moorereason authored and pelletier committed Aug 22, 2016
1 parent e627103 commit bfe4a7e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
3 changes: 2 additions & 1 deletion cmd/test_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/pelletier/go-toml"
"io/ioutil"
"log"
"os"
"time"

"github.com/pelletier/go-toml"
)

func main() {
Expand Down
19 changes: 10 additions & 9 deletions cmd/tomljson/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package main

import (
"github.com/pelletier/go-toml"
"io"
"os"
"encoding/json"
"flag"
"fmt"
"encoding/json"
"io"
"os"

"github.com/pelletier/go-toml"
)

func main() {
Expand Down Expand Up @@ -40,27 +41,27 @@ func processMain(files []string, defaultInput io.Reader, output io.Writer, error
printError(err, errorOutput)
return -1
}
io.WriteString(output, s + "\n")
io.WriteString(output, s+"\n")
return 0
}

func printError(err error, output io.Writer) {
io.WriteString(output, err.Error() + "\n")
io.WriteString(output, err.Error()+"\n")
}

func reader(r io.Reader) (string, error) {
tree, err := toml.LoadReader(r)
if err != nil {
return "", err
}
return mapToJson(tree)
return mapToJSON(tree)
}

func mapToJson(tree *toml.TomlTree) (string, error) {
func mapToJSON(tree *toml.TomlTree) (string, error) {
treeMap := tree.ToMap()
bytes, err := json.MarshalIndent(treeMap, "", " ")
if err != nil {
return "", err
}
return string(bytes[:]), nil
}
}
10 changes: 4 additions & 6 deletions cmd/tomljson/main_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"testing"
"strings"
"bytes"
"os"
"io/ioutil"
"os"
"strings"
"testing"
)

func expectBufferEquality(t *testing.T, name string, buffer *bytes.Buffer, expected string) {
Expand All @@ -32,7 +32,6 @@ func expectProcessMainResults(t *testing.T, input string, args []string, exitCod
}
}


func TestProcessMainReadFromStdin(t *testing.T) {
input := `
[mytoml]
Expand All @@ -54,7 +53,6 @@ func TestProcessMainReadFromFile(t *testing.T) {
[mytoml]
a = 42`


tmpfile, err := ioutil.TempFile("", "example.toml")
if err != nil {
t.Fatal(err)
Expand All @@ -81,4 +79,4 @@ func TestProcessMainReadFromMissingFile(t *testing.T) {
expectedError := `open /this/file/does/not/exist: no such file or directory
`
expectProcessMainResults(t, ``, []string{"/this/file/does/not/exist"}, -1, ``, expectedError)
}
}
5 changes: 3 additions & 2 deletions tomltree_conversions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Tools to convert a TomlTree to different representations
package toml

// Tools to convert a TomlTree to different representations

import (
"fmt"
"strconv"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (t *TomlTree) ToMap() map[string]interface{} {
for k, v := range t.values {
switch node := v.(type) {
case []*TomlTree:
array := make([]interface{}, 0)
var array []interface{}
for _, item := range node {
array = append(array, item.ToMap())
}
Expand Down
5 changes: 2 additions & 3 deletions tomltree_conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ func TestTomlTreeConversionToMapWithTablesInMultipleChunks(t *testing.T) {
expected := map[string]interface{}{
"menu": map[string]interface{}{
"main": []interface{}{
map[string]interface{}{"a": "menu 1", "b": "menu 2", },
map[string]interface{}{"c": "menu 3", "d": "menu 4", },
map[string]interface{}{"a": "menu 1", "b": "menu 2"},
map[string]interface{}{"c": "menu 3", "d": "menu 4"},
},
},
}
treeMap := tree.ToMap()


testMaps(t, treeMap, expected)
}

0 comments on commit bfe4a7e

Please sign in to comment.