Skip to content

Instantly share code, notes, and snippets.

@clarkritchie
Created October 6, 2022 17:44
Show Gist options
  • Save clarkritchie/9060520f9721378344efdfa8fc5d21cc to your computer and use it in GitHub Desktop.
Save clarkritchie/9060520f9721378344efdfa8fc5d21cc to your computer and use it in GitHub Desktop.
// You can edit this code!
// Click here and start typing.
package main
import (
"fmt"
"net/mail"
"strings"
)
func emailValid(email string) bool {
_, err := mail.ParseAddress(email)
return err == nil
}
func main() {
for _, email := range []string{
"good@exmaple.com",
"bad-example",
"foo bar@bar.com ",
} {
fmt.Printf("%18s valid: %t\n", email, emailValid(email))
}
var data = map[string]interface{}{
"event": "something",
"customer_properties": map[string]interface{}{
"$email": strings.TrimSpace("hello@clark.co"),
},
"properties": map[string]interface{}{
"lang": "en",
},
}
cprops, _ := data["customer_properties"].(map[string]interface{})
email, _ := cprops["$email"].(string)
if emailValid(email) {
fmt.Printf("email '%s' is valid\n", email)
} else {
fmt.Printf("email '%s' is NOT valid\n", email)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment