Skip to content

Commit bb34672

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 bb34672

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

address_types.go

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package proton
22

3+
import "fmt"
4+
35
type Address struct {
46
ID string
57
Email string
@@ -27,6 +29,14 @@ const (
2729
AddressStatusDeleting
2830
)
2931

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

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

0 commit comments

Comments
 (0)