From d8b77c9e932365a0385b862c29a590c8743cad30 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 5 Sep 2024 16:52:59 +0200 Subject: [PATCH] Shorten CommentType#UnmarshalText() by just calling CommentType#UnmarshalJSON(). The implementations behave identically. (Just like for AcknowledgementState, NotificationStates, NotificationTypes and StateType.) --- pkg/icingadb/types/comment_type.go | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/pkg/icingadb/types/comment_type.go b/pkg/icingadb/types/comment_type.go index 86bb092c6..88240f4db 100644 --- a/pkg/icingadb/types/comment_type.go +++ b/pkg/icingadb/types/comment_type.go @@ -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. @@ -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.