Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Oct 8, 2024
1 parent 4fdff46 commit 06e0739
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

install-tools:
@mkdir -p $(GO_TOOLS_BIN_PATH)
@which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.60.3
@which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.61.0
@grep '_' tools.go | sed 's/"//g' | awk '{print $$2}' | xargs go install

.PHONY: install-tools
Expand Down
10 changes: 6 additions & 4 deletions pkg/utils/reflectutil/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ func FindFieldByJSONTag(t reflect.Type, tags []string) reflect.Type {
if t.Kind() != reflect.Struct {
return nil
}
tag := tags[0]
tagRemain := tags[1:]
for i := 0; i < t.NumField(); i++ {
jsonTag := t.Field(i).Tag.Get("json")
if i := strings.Index(jsonTag, ","); i != -1 { // trim 'foobar,string' to 'foobar'
jsonTag = jsonTag[:i]
if j := strings.Index(jsonTag, ","); j != -1 { // trim 'foobar,string' to 'foobar'
jsonTag = jsonTag[:j]
}
if jsonTag == tags[0] { //nolint:gosec
return FindFieldByJSONTag(t.Field(i).Type, tags[1:]) //nolint:gosec
if jsonTag == tag {
return FindFieldByJSONTag(t.Field(i).Type, tagRemain)
}
}
return nil
Expand Down

0 comments on commit 06e0739

Please sign in to comment.