Commit a3f35263 authored by 李志信's avatar 李志信

fix: fix fmt bug

parent a410c209
......@@ -15,12 +15,14 @@ github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
......@@ -29,5 +31,6 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepx
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package jsonStructParser
package jparser
import (
"fmt"
......@@ -44,20 +44,20 @@ func newJSONStructParser() *jsonStructParser {
}
}
func init() {
// JsonFile2Interface parse json @filePath to interface
func JsonFile2Interface(filePath string) (interface{}, error) {
defer func() {
defaultJSONStructParser = newJSONStructParser()
}()
return defaultJSONStructParser.JSONFilePath2Struct(filePath)
}
var defaultJSONStructParser *jsonStructParser
// JsonFile2Interface parse json @file to interface
func JsonFile2Interface(file []byte) (interface{}, error) {
defer func() {
func init() {
defaultJSONStructParser = newJSONStructParser()
}()
return defaultJSONStructParser.Jsonfile2Struct(string(file))
}
var defaultJSONStructParser *jsonStructParser
func RemoveTargetNameField(v interface{}, targetName string) interface{} {
defer func() {
defaultJSONStructParser = newJSONStructParser()
......@@ -168,8 +168,8 @@ func (jsp *jsonStructParser) json2Struct(jsonData []byte) interface{} {
return s
}
// Jsonfile2Struct read file from @filePath and parse data to interface
func (jsp *jsonStructParser) Jsonfile2Struct(filePath string) (interface{}, error) {
// JSONFilePath2Struct read file from @filePath and parse data to interface
func (jsp *jsonStructParser) JSONFilePath2Struct(filePath string) (interface{}, error) {
jsonData, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package jsonStructParser
package jparser
import (
"testing"
......@@ -27,7 +27,7 @@ import (
func Test_newJsonStructParser(t *testing.T) {
path := "./user.json"
jparser := newJsonStructParser()
_, err := jparser.Jsonfile2Struct(path)
jParser := newJSONStructParser()
_, err := jParser.JSONFilePath2Struct(path)
assert.Nil(t, err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment