Skip to content

Commit

Permalink
chore: sonarlint
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesserli committed May 13, 2024
1 parent 2857125 commit 21bff66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM golang:1 as builder
FROM golang:1 AS builder
LABEL maintainer="Joel Messerli <hi.github@peg.nu>"
WORKDIR /go/src/github.com/jmesserli/nx
COPY . .
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /go/bin/nx .

FROM alpine:latest
FROM alpine:3
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /root/
COPY --from=builder /go/bin/nx .
Expand Down
14 changes: 8 additions & 6 deletions tagparser/tagparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
)

const NoValueErrStr = "no value available"

var tagRegex = regexp.MustCompile("^(\\w+),ns:(\\w+)$")

type annotatedField struct {
Expand Down Expand Up @@ -103,7 +105,7 @@ func findValueForField(field annotatedField, tags []model.Tag) (interface{}, err

if sKind == reflect.String {
if len(strValues) == 0 {
return nil, fmt.Errorf("no value available")
return nil, fmt.Errorf(NoValueErrStr)
}
return strValues, nil
} else if sKind == reflect.Int {
Expand All @@ -123,14 +125,14 @@ func findValueForField(field annotatedField, tags []model.Tag) (interface{}, err
} else if fKind == reflect.String {
if len(strValues) == 0 {
//fmt.Printf("warn: No values available for string field <%s>. Returning empty string.\n", field.sField.Name)
return "", fmt.Errorf("no value available")
return "", fmt.Errorf(NoValueErrStr)
}

return strValues[0], nil
} else if fKind == reflect.Int {
if len(strValues) == 0 {
//fmt.Printf("warn: No values available for int field <%s>. Returning 0.\n", field.sField.Name)
return 0, fmt.Errorf("no value available")
return 0, fmt.Errorf(NoValueErrStr)
}

for _, val := range strValues {
Expand All @@ -144,11 +146,11 @@ func findValueForField(field annotatedField, tags []model.Tag) (interface{}, err
}

//fmt.Printf("warn: No values available for int field <%s>. Returning 0.\n", field.sField.Name)
return 0, fmt.Errorf("no value available")
return 0, fmt.Errorf(NoValueErrStr)
} else if fKind == reflect.Bool {
if len(strValues) == 0 {
//fmt.Printf("warn: No values available for bool field <%s>. Returning false.\n", field.sField.Name)
return false, fmt.Errorf("no value available")
return false, fmt.Errorf(NoValueErrStr)
}

for _, val := range strValues {
Expand All @@ -162,7 +164,7 @@ func findValueForField(field annotatedField, tags []model.Tag) (interface{}, err
}

//fmt.Printf("warn: No values available for bool field <%s>. Returning false.\n", field.sField.Name)
return false, fmt.Errorf("no value available")
return false, fmt.Errorf(NoValueErrStr)
}

panic(fmt.Sprintf("Unsupported field type <%v>", fKind))
Expand Down

0 comments on commit 21bff66

Please sign in to comment.