Skip to content

Commit

Permalink
Merge pull request #805 from Icinga/CommentType
Browse files Browse the repository at this point in the history
Shorten CommentType#UnmarshalText()
  • Loading branch information
lippserd authored Oct 7, 2024
2 parents e8ed78e + d8b77c9 commit 187288c
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions pkg/icingadb/types/comment_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"github.com/icinga/icinga-go-library/types"
"github.com/pkg/errors"
"strconv"
)

// CommentType specifies a comment's origin's kind.
Expand All @@ -30,25 +29,7 @@ func (ct *CommentType) UnmarshalJSON(data []byte) error {

// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (ct *CommentType) UnmarshalText(text []byte) error {
s := string(text)

i, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return types.CantParseUint64(err, s)
}

c := CommentType(i)
if uint64(c) != i {
// Truncated due to above cast, obviously too high
return badCommentType(s)
}

if _, ok := commentTypes[c]; !ok {
return badCommentType(s)
}

*ct = c
return nil
return ct.UnmarshalJSON(text)
}

// Value implements the driver.Valuer interface.
Expand Down

0 comments on commit 187288c

Please sign in to comment.