barcodes/formatting/email.go

49 lines
857 B
Go

package formatting
import (
"encoding/json"
"net/url"
)
type EMail struct {
Address string `json:"address,omitempty"`
Cc *string `json:"cc,omitempty"`
Bcc *string `json:"bcc,omitempty"`
Subject *string `json:"subject,omitempty"`
Content *string `json:"content,omitempty"`
}
func formatEMail(input string) (string, error) {
var email EMail
err := json.Unmarshal([]byte(input), &email)
if err != nil {
return "", err
}
query := url.Values{}
if email.Subject != nil {
query.Add("subject", *email.Subject)
}
if email.Cc != nil {
query.Add("cc", *email.Cc)
}
if email.Bcc != nil {
query.Add("bcc", *email.Bcc)
}
if email.Content != nil {
query.Add("body", *email.Content)
}
barcodeString := "mailto:" + email.Address
if len(query) > 0 {
barcodeString += "?" + query.Encode()
}
return barcodeString, err
}