aboutsummaryrefslogtreecommitdiff
path: root/contact.go
diff options
context:
space:
mode:
Diffstat (limited to 'contact.go')
-rw-r--r--contact.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/contact.go b/contact.go
index 71b4ecd..2a69ebe 100644
--- a/contact.go
+++ b/contact.go
@@ -48,14 +48,27 @@ func (ph Phone) MarshalText() ([]byte, error) {
return []byte("tel:" + ph), nil
}
-func NewContacts(email, phone string) (Contacts, error) {
+func NewMail(email string) (Mail, error) {
m, err := mail.ParseAddress(email)
if err != nil {
+ return "", err
+ }
+ return Mail(m.Address), nil
+}
+
+func NewPhone(phone string) (Phone, error) {
+ return Phone(phone), nil
+}
+
+func NewContacts(email, phone string) (Contacts, error) {
+ m, err := NewMail(email)
+ if err != nil {
return nil, err
}
- c := Contacts{Mail(m.Address)}
+ c := Contacts{m}
if phone != "" {
- c = append(c, Phone(phone))
+ p, _ := NewPhone(phone)
+ c = append(c, p)
}
return c, nil
}