Skip to content

Commit

Permalink
Shorten CommentType#UnmarshalText()
Browse files Browse the repository at this point in the history
by just calling CommentType#UnmarshalJSON().
The implementations behave identically. (Just like for AcknowledgementState,
NotificationStates, NotificationTypes and StateType.)
  • Loading branch information
Al2Klimov committed Sep 16, 2024
1 parent 806a2ff commit f222c51
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 f222c51

Please sign in to comment.