Skip to content

Commit 1445aa1

Browse files
committed
feat: support meaningful string casts of address status/type
Support casting the type back to a meaningful string.
1 parent 98a73ff commit 1445aa1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

address_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ const (
2727
AddressStatusDeleting
2828
)
2929

30+
func (s AddressStatus) String() string {
31+
statusStrings := [...]string{"disabled", "enabled", "deleting" }
32+
if s < proton.AddressStatusDisabled || s > proton.AddressStatusDeleting {
33+
return fmt.Sprintf("Unknown Status (%d)", s)
34+
}
35+
return statusStrings[s]
36+
}
37+
3038
type AddressType int
3139

3240
const (
@@ -36,3 +44,13 @@ const (
3644
AddressTypePremium
3745
AddressTypeExternal
3846
)
47+
48+
func (a AddressType) String() string {
49+
typeStrings := [...]string{"original", "alias", "custom", "premium", "external" }
50+
if a < proton.AddressTypeOriginal || a > proton.AddressTypeExternal {
51+
return fmt.Sprintf("Unknown Status (%d)", a)
52+
}
53+
54+
// Proton API defines the start type as `iota + 1`
55+
return typeStrings[a-1]
56+
}

0 commit comments

Comments
 (0)