Fix gofmt and golint issues (#90)
This commit is contained in:
committed by
Thomas Pelletier
parent
e6271032cc
commit
bfe4a7e160
+2
-1
@@ -3,11 +3,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pelletier/go-toml"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
+10
-9
@@ -1,12 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pelletier/go-toml"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -40,12 +41,12 @@ func processMain(files []string, defaultInput io.Reader, output io.Writer, error
|
|||||||
printError(err, errorOutput)
|
printError(err, errorOutput)
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
io.WriteString(output, s + "\n")
|
io.WriteString(output, s+"\n")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func printError(err error, output io.Writer) {
|
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) {
|
func reader(r io.Reader) (string, error) {
|
||||||
@@ -53,14 +54,14 @@ func reader(r io.Reader) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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()
|
treeMap := tree.ToMap()
|
||||||
bytes, err := json.MarshalIndent(treeMap, "", " ")
|
bytes, err := json.MarshalIndent(treeMap, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return string(bytes[:]), nil
|
return string(bytes[:]), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"strings"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func expectBufferEquality(t *testing.T, name string, buffer *bytes.Buffer, expected string) {
|
func expectBufferEquality(t *testing.T, name string, buffer *bytes.Buffer, expected string) {
|
||||||
@@ -32,7 +32,6 @@ func expectProcessMainResults(t *testing.T, input string, args []string, exitCod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestProcessMainReadFromStdin(t *testing.T) {
|
func TestProcessMainReadFromStdin(t *testing.T) {
|
||||||
input := `
|
input := `
|
||||||
[mytoml]
|
[mytoml]
|
||||||
@@ -54,7 +53,6 @@ func TestProcessMainReadFromFile(t *testing.T) {
|
|||||||
[mytoml]
|
[mytoml]
|
||||||
a = 42`
|
a = 42`
|
||||||
|
|
||||||
|
|
||||||
tmpfile, err := ioutil.TempFile("", "example.toml")
|
tmpfile, err := ioutil.TempFile("", "example.toml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -81,4 +79,4 @@ func TestProcessMainReadFromMissingFile(t *testing.T) {
|
|||||||
expectedError := `open /this/file/does/not/exist: no such file or directory
|
expectedError := `open /this/file/does/not/exist: no such file or directory
|
||||||
`
|
`
|
||||||
expectProcessMainResults(t, ``, []string{"/this/file/does/not/exist"}, -1, ``, expectedError)
|
expectProcessMainResults(t, ``, []string{"/this/file/does/not/exist"}, -1, ``, expectedError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Tools to convert a TomlTree to different representations
|
|
||||||
package toml
|
package toml
|
||||||
|
|
||||||
|
// Tools to convert a TomlTree to different representations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -126,7 +127,7 @@ func (t *TomlTree) ToMap() map[string]interface{} {
|
|||||||
for k, v := range t.values {
|
for k, v := range t.values {
|
||||||
switch node := v.(type) {
|
switch node := v.(type) {
|
||||||
case []*TomlTree:
|
case []*TomlTree:
|
||||||
array := make([]interface{}, 0)
|
var array []interface{}
|
||||||
for _, item := range node {
|
for _, item := range node {
|
||||||
array = append(array, item.ToMap())
|
array = append(array, item.ToMap())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,13 +92,12 @@ func TestTomlTreeConversionToMapWithTablesInMultipleChunks(t *testing.T) {
|
|||||||
expected := map[string]interface{}{
|
expected := map[string]interface{}{
|
||||||
"menu": map[string]interface{}{
|
"menu": map[string]interface{}{
|
||||||
"main": []interface{}{
|
"main": []interface{}{
|
||||||
map[string]interface{}{"a": "menu 1", "b": "menu 2", },
|
map[string]interface{}{"a": "menu 1", "b": "menu 2"},
|
||||||
map[string]interface{}{"c": "menu 3", "d": "menu 4", },
|
map[string]interface{}{"c": "menu 3", "d": "menu 4"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
treeMap := tree.ToMap()
|
treeMap := tree.ToMap()
|
||||||
|
|
||||||
|
|
||||||
testMaps(t, treeMap, expected)
|
testMaps(t, treeMap, expected)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user