From 26c889ad6607d75fc50ca4d6daefe21fc3616e2b Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Thu, 22 Apr 2021 09:53:47 +0200 Subject: [PATCH] types.NotificationTypes: Implement UnmarshalText() --- pkg/types/notification_types.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/types/notification_types.go b/pkg/types/notification_types.go index f6b8714f..0997f648 100644 --- a/pkg/types/notification_types.go +++ b/pkg/types/notification_types.go @@ -2,6 +2,7 @@ package types import ( "database/sql/driver" + "encoding" "encoding/json" "fmt" ) @@ -29,6 +30,11 @@ func (nt *NotificationTypes) UnmarshalJSON(bytes []byte) error { return nil } +// UnmarshalText implements the encoding.TextUnmarshaler interface. +func (nt *NotificationTypes) UnmarshalText(text []byte) error { + return nt.UnmarshalJSON(text) +} + // Value implements the driver.Valuer interface. func (nt NotificationTypes) Value() (driver.Value, error) { if nt&^allNotificationTypes == 0 { @@ -73,7 +79,8 @@ var allNotificationTypes = func() NotificationTypes { // Assert interface compliance. var ( - _ error = BadNotificationTypes{} - _ json.Unmarshaler = (*NotificationTypes)(nil) - _ driver.Valuer = NotificationTypes(0) + _ error = BadNotificationTypes{} + _ json.Unmarshaler = (*NotificationTypes)(nil) + _ encoding.TextUnmarshaler = (*NotificationTypes)(nil) + _ driver.Valuer = NotificationTypes(0) )