Skip to content

Commit c81662b

Browse files
Belyenochi御锋
andauthored
refactor(extractor): export ParseJsonPath function (#105)
* refactor(extractor): export ParseJsonPath function * chore(extractor): rename ParseJsonPath into ParseJSONPath --------- Co-authored-by: 御锋 <[email protected]>
1 parent 8bbf42c commit c81662b

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

extractor/extractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func New(jsonPaths []string, opts ...Option) (Extractor, error) {
5151
}
5252

5353
for _, p := range jsonPaths {
54-
parser, err := parseJsonPath(p)
54+
parser, err := ParseJSONPath(p)
5555
if err != nil {
5656
return nil, fmt.Errorf("error in parsing path %q: %w", p, err)
5757
}

extractor/jsonpath_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type jsonPathTest struct {
3434
}
3535

3636
func (t *jsonPathTest) Prepare(opts ...Option) (Extractor, error) {
37-
parser, err := parseJsonPath(t.template)
37+
parser, err := ParseJSONPath(t.template)
3838
if err != nil {
3939
return nil, err
4040
}
@@ -178,7 +178,7 @@ func TestJSONPath(t *testing.T) {
178178
}
179179

180180
func TestJSONPathReuse(t *testing.T) {
181-
parser, err := parseJsonPath(`{.spec.containers[*]['name', 'image']}`)
181+
parser, err := ParseJSONPath(`{.spec.containers[*]['name', 'image']}`)
182182
require.NoError(t, err)
183183
extractor := newJSONPatch(options{ignoreMissingKey: true}, parser)
184184
got, err := extractor.Extract(podData)

extractor/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import (
2424
"k8s.io/client-go/util/jsonpath"
2525
)
2626

27-
// parseJsonPath is unlike the jsonpath.parseJsonPath, which supports multi-paths input.
27+
// ParseJSONPath is unlike the jsonpath.ParseJSONPath, which supports multi-paths input.
2828
// The input like `{.kind} {.apiVersion}` or
2929
// `{range .spec.containers[*]}{.name}{end}` will result in an error.
3030
//
3131
// It also relaxes the JSONPath expressions internally,
3232
// so inputs like `.kind` (without curly braces) are acceptable.
33-
func parseJsonPath(text string) (*jsonpath.Parser, error) {
33+
func ParseJSONPath(text string) (*jsonpath.Parser, error) {
3434
relaxed, err := RelaxedJSONPathExpression(text)
3535
if err != nil {
3636
return nil, err

extractor/parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestParse(t *testing.T) {
3737
}
3838
for _, tt := range tests {
3939
t.Run(tt.name, func(t *testing.T) {
40-
got, err := parseJsonPath(tt.text)
40+
got, err := ParseJSONPath(tt.text)
4141
if tt.wantErr {
4242
require.Error(t, err)
4343
} else {

0 commit comments

Comments
 (0)