Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
77e347b8
Commit
77e347b8
authored
Aug 10, 2017
by
Nikhita Raghunath
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jsonpath: fix comments
avoid named return errors fix compile error
parent
7ef5cc23
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
jsonpath.go
staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go
+15
-13
node.go
staging/src/k8s.io/client-go/util/jsonpath/node.go
+2
-2
No files found.
staging/src/k8s.io/client-go/util/jsonpath/jsonpath.go
View file @
77e347b8
...
@@ -29,8 +29,8 @@ import (
...
@@ -29,8 +29,8 @@ import (
type
JSONPath
struct
{
type
JSONPath
struct
{
name
string
name
string
parser
*
Parser
parser
*
Parser
stack
[][]
reflect
.
Value
//push and pop values in different scopes
stack
[][]
reflect
.
Value
//
push and pop values in different scopes
cur
[]
reflect
.
Value
//current scope values
cur
[]
reflect
.
Value
//
current scope values
beginRange
int
beginRange
int
inRange
int
inRange
int
endRange
int
endRange
int
...
@@ -38,6 +38,7 @@ type JSONPath struct {
...
@@ -38,6 +38,7 @@ type JSONPath struct {
allowMissingKeys
bool
allowMissingKeys
bool
}
}
// New creates a new JSONPath with the given name.
func
New
(
name
string
)
*
JSONPath
{
func
New
(
name
string
)
*
JSONPath
{
return
&
JSONPath
{
return
&
JSONPath
{
name
:
name
,
name
:
name
,
...
@@ -54,13 +55,14 @@ func (j *JSONPath) AllowMissingKeys(allow bool) *JSONPath {
...
@@ -54,13 +55,14 @@ func (j *JSONPath) AllowMissingKeys(allow bool) *JSONPath {
return
j
return
j
}
}
// Parse parse the given template, return error
// Parse parses the given template and returns an error.
func
(
j
*
JSONPath
)
Parse
(
text
string
)
(
err
error
)
{
func
(
j
*
JSONPath
)
Parse
(
text
string
)
error
{
var
err
error
j
.
parser
,
err
=
Parse
(
j
.
name
,
text
)
j
.
parser
,
err
=
Parse
(
j
.
name
,
text
)
return
return
err
}
}
// Execute bounds data into template and write
the result
// Execute bounds data into template and write
s the result.
func
(
j
*
JSONPath
)
Execute
(
wr
io
.
Writer
,
data
interface
{})
error
{
func
(
j
*
JSONPath
)
Execute
(
wr
io
.
Writer
,
data
interface
{})
error
{
fullResults
,
err
:=
j
.
FindResults
(
data
)
fullResults
,
err
:=
j
.
FindResults
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -89,12 +91,12 @@ func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error) {
...
@@ -89,12 +91,12 @@ func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error) {
return
nil
,
err
return
nil
,
err
}
}
//encounter an end node, break the current block
//
encounter an end node, break the current block
if
j
.
endRange
>
0
&&
j
.
endRange
<=
j
.
inRange
{
if
j
.
endRange
>
0
&&
j
.
endRange
<=
j
.
inRange
{
j
.
endRange
-=
1
j
.
endRange
-=
1
break
break
}
}
//encounter a range node, start a range loop
//
encounter a range node, start a range loop
if
j
.
beginRange
>
0
{
if
j
.
beginRange
>
0
{
j
.
beginRange
-=
1
j
.
beginRange
-=
1
j
.
inRange
+=
1
j
.
inRange
+=
1
...
@@ -116,7 +118,7 @@ func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error) {
...
@@ -116,7 +118,7 @@ func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error) {
return
fullResult
,
nil
return
fullResult
,
nil
}
}
// PrintResults write the results into writer
// PrintResults write
s
the results into writer
func
(
j
*
JSONPath
)
PrintResults
(
wr
io
.
Writer
,
results
[]
reflect
.
Value
)
error
{
func
(
j
*
JSONPath
)
PrintResults
(
wr
io
.
Writer
,
results
[]
reflect
.
Value
)
error
{
for
i
,
r
:=
range
results
{
for
i
,
r
:=
range
results
{
text
,
err
:=
j
.
evalToText
(
r
)
text
,
err
:=
j
.
evalToText
(
r
)
...
@@ -214,7 +216,7 @@ func (j *JSONPath) evalIdentifier(input []reflect.Value, node *IdentifierNode) (
...
@@ -214,7 +216,7 @@ func (j *JSONPath) evalIdentifier(input []reflect.Value, node *IdentifierNode) (
j
.
beginRange
+=
1
j
.
beginRange
+=
1
results
=
input
results
=
input
case
"end"
:
case
"end"
:
if
j
.
endRange
<
j
.
inRange
{
//inside a loop, break the current block
if
j
.
endRange
<
j
.
inRange
{
//
inside a loop, break the current block
j
.
endRange
+=
1
j
.
endRange
+=
1
break
break
}
}
...
@@ -366,7 +368,7 @@ func (j *JSONPath) evalField(input []reflect.Value, node *FieldNode) ([]reflect.
...
@@ -366,7 +368,7 @@ func (j *JSONPath) evalField(input []reflect.Value, node *FieldNode) ([]reflect.
return
results
,
nil
return
results
,
nil
}
}
// evalWildcard extract all contents of the given value
// evalWildcard extract
s
all contents of the given value
func
(
j
*
JSONPath
)
evalWildcard
(
input
[]
reflect
.
Value
,
node
*
WildcardNode
)
([]
reflect
.
Value
,
error
)
{
func
(
j
*
JSONPath
)
evalWildcard
(
input
[]
reflect
.
Value
,
node
*
WildcardNode
)
([]
reflect
.
Value
,
error
)
{
results
:=
[]
reflect
.
Value
{}
results
:=
[]
reflect
.
Value
{}
for
_
,
value
:=
range
input
{
for
_
,
value
:=
range
input
{
...
@@ -393,7 +395,7 @@ func (j *JSONPath) evalWildcard(input []reflect.Value, node *WildcardNode) ([]re
...
@@ -393,7 +395,7 @@ func (j *JSONPath) evalWildcard(input []reflect.Value, node *WildcardNode) ([]re
return
results
,
nil
return
results
,
nil
}
}
// evalRecursive visit
the given value recursively and push
all of them to result
// evalRecursive visit
s the given value recursively and pushes
all of them to result
func
(
j
*
JSONPath
)
evalRecursive
(
input
[]
reflect
.
Value
,
node
*
RecursiveNode
)
([]
reflect
.
Value
,
error
)
{
func
(
j
*
JSONPath
)
evalRecursive
(
input
[]
reflect
.
Value
,
node
*
RecursiveNode
)
([]
reflect
.
Value
,
error
)
{
result
:=
[]
reflect
.
Value
{}
result
:=
[]
reflect
.
Value
{}
for
_
,
value
:=
range
input
{
for
_
,
value
:=
range
input
{
...
@@ -429,7 +431,7 @@ func (j *JSONPath) evalRecursive(input []reflect.Value, node *RecursiveNode) ([]
...
@@ -429,7 +431,7 @@ func (j *JSONPath) evalRecursive(input []reflect.Value, node *RecursiveNode) ([]
return
result
,
nil
return
result
,
nil
}
}
// evalFilter filter array according to FilterNode
// evalFilter filter
s
array according to FilterNode
func
(
j
*
JSONPath
)
evalFilter
(
input
[]
reflect
.
Value
,
node
*
FilterNode
)
([]
reflect
.
Value
,
error
)
{
func
(
j
*
JSONPath
)
evalFilter
(
input
[]
reflect
.
Value
,
node
*
FilterNode
)
([]
reflect
.
Value
,
error
)
{
results
:=
[]
reflect
.
Value
{}
results
:=
[]
reflect
.
Value
{}
for
_
,
value
:=
range
input
{
for
_
,
value
:=
range
input
{
...
...
staging/src/k8s.io/client-go/util/jsonpath/node.go
View file @
77e347b8
...
@@ -131,13 +131,13 @@ func (f *IdentifierNode) String() string {
...
@@ -131,13 +131,13 @@ func (f *IdentifierNode) String() string {
// ParamsEntry holds param information for ArrayNode
// ParamsEntry holds param information for ArrayNode
type
ParamsEntry
struct
{
type
ParamsEntry
struct
{
Value
int
Value
int
Known
bool
//whether the value is known when parse it
Known
bool
//
whether the value is known when parse it
}
}
// ArrayNode holds start, end, step information for array index selection
// ArrayNode holds start, end, step information for array index selection
type
ArrayNode
struct
{
type
ArrayNode
struct
{
NodeType
NodeType
Params
[
3
]
ParamsEntry
//start, end, step
Params
[
3
]
ParamsEntry
//
start, end, step
}
}
func
newArray
(
params
[
3
]
ParamsEntry
)
*
ArrayNode
{
func
newArray
(
params
[
3
]
ParamsEntry
)
*
ArrayNode
{
...
...
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