Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
a3f35263
Commit
a3f35263
authored
Dec 01, 2020
by
李志信
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix fmt bug
parent
a410c209
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
14 deletions
+17
-14
go.sum
go.sum
+3
-0
parser.go
jparser/parser.go
+11
-11
parser_test.go
jparser/parser_test.go
+3
-3
user.json
jparser/user.json
+0
-0
No files found.
go.sum
View file @
a3f35263
...
...
@@ -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=
j
son_struct_
parser/parser.go
→
jparser/parser.go
View file @
a3f35263
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
j
sonStructP
arser
package
j
p
arser
import
(
"fmt"
...
...
@@ -44,20 +44,20 @@ func newJSONStructParser() *jsonStructParser {
}
}
// JsonFile2Interface parse json @filePath to interface
func
JsonFile2Interface
(
filePath
string
)
(
interface
{},
error
)
{
defer
func
()
{
defaultJSONStructParser
=
newJSONStructParser
()
}()
return
defaultJSONStructParser
.
JSONFilePath2Struct
(
filePath
)
}
func
init
()
{
defaultJSONStructParser
=
newJSONStructParser
()
}
var
defaultJSONStructParser
*
jsonStructParser
// JsonFile2Interface parse json @file to interface
func
JsonFile2Interface
(
file
[]
byte
)
(
interface
{},
error
)
{
defer
func
()
{
defaultJSONStructParser
=
newJSONStructParser
()
}()
return
defaultJSONStructParser
.
Jsonfile2Struct
(
string
(
file
))
}
func
RemoveTargetNameField
(
v
interface
{},
targetName
string
)
interface
{}
{
defer
func
()
{
defaultJSONStructParser
=
newJSONStructParser
()
...
...
@@ -168,8 +168,8 @@ func (jsp *jsonStructParser) json2Struct(jsonData []byte) interface{} {
return
s
}
// J
sonfile
2Struct read file from @filePath and parse data to interface
func
(
jsp
*
jsonStructParser
)
J
sonfile
2Struct
(
filePath
string
)
(
interface
{},
error
)
{
// J
SONFilePath
2Struct read file from @filePath and parse data to interface
func
(
jsp
*
jsonStructParser
)
J
SONFilePath
2Struct
(
filePath
string
)
(
interface
{},
error
)
{
jsonData
,
err
:=
ioutil
.
ReadFile
(
filePath
)
if
err
!=
nil
{
return
nil
,
err
...
...
j
son_struct_
parser/parser_test.go
→
jparser/parser_test.go
View file @
a3f35263
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
j
sonStructP
arser
package
j
p
arser
import
(
"testing"
...
...
@@ -27,7 +27,7 @@ import (
func
Test_newJsonStructParser
(
t
*
testing
.
T
)
{
path
:=
"./user.json"
j
parser
:=
newJson
StructParser
()
_
,
err
:=
j
parser
.
Jsonfile
2Struct
(
path
)
j
Parser
:=
newJSON
StructParser
()
_
,
err
:=
j
Parser
.
JSONFilePath
2Struct
(
path
)
assert
.
Nil
(
t
,
err
)
}
j
son_struct_
parser/user.json
→
jparser/user.json
View file @
a3f35263
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment