From 9e6f4b2e54fe5ba83eae1849ef758e109f59580d Mon Sep 17 00:00:00 2001 From: Mark Ferrell Date: Mon, 27 Jan 2025 06:46:25 -0800 Subject: [PATCH] feat: support meaningful string casts of address status/type Support casting the type back to a meaningful string. --- address_types.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/address_types.go b/address_types.go index cb46b5f..e34c4ab 100644 --- a/address_types.go +++ b/address_types.go @@ -1,5 +1,7 @@ package proton +import "fmt" + type Address struct { ID string Email string @@ -27,6 +29,14 @@ const ( AddressStatusDeleting ) +func (s AddressStatus) String() string { + statusStrings := [...]string{"disabled", "enabled", "deleting" } + if s < AddressStatusDisabled || s > AddressStatusDeleting { + return fmt.Sprintf("Unknown Status (%d)", s) + } + return statusStrings[s] +} + type AddressType int const ( @@ -42,3 +52,13 @@ const ( func (a Address) IsBYOEAddress() bool { return bool(a.Send) && a.Type == AddressTypeExternal } + +func (a AddressType) String() string { + typeStrings := [...]string{"original", "alias", "custom", "premium", "external" } + if a < AddressTypeOriginal || a > AddressTypeExternal { + return fmt.Sprintf("Unknown Status (%d)", a) + } + + // Proton API defines the start type as `iota + 1` + return typeStrings[a-1] +}