From c0dc38b656ec84a401a99f2f97f6af79c4e66398 Mon Sep 17 00:00:00 2001 From: insomniac Date: Sun, 19 Aug 2018 19:58:01 +0100 Subject: Added String methods for types (#140) * Added String methods for types * Reverted change on bsdp.OptionCode --- dhcpv6/types.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'dhcpv6') diff --git a/dhcpv6/types.go b/dhcpv6/types.go index 1ef5938..9c9f84f 100644 --- a/dhcpv6/types.go +++ b/dhcpv6/types.go @@ -1,5 +1,9 @@ package dhcpv6 +import ( + "log" +) + // from http://www.networksorcery.com/enp/protocol/dhcpv6.htm // MessageType represents the kind of DHCPv6 message. @@ -28,13 +32,18 @@ const ( MessageTypeLeaseQueryData MessageType = 17 ) +func (m MessageType) String() string { + if s, ok := MessageTypeToStringMap[m]; ok { + return s + } + return "Unknown" +} + // MessageTypeToString converts a MessageType to a human-readable string // representation. func MessageTypeToString(t MessageType) string { - if m, ok := MessageTypeToStringMap[t]; ok { - return m - } - return "Unknown" + log.Printf("Warning: MessageTypeToString is deprecated and will be removed, use MessageType.String() instead") + return t.String() } // MessageTypeToStringMap contains the mapping of MessageTypes to human-readable -- cgit v1.2.3