github.com/go-email-validator/go-email-validator@v0.0.0-20230409163946-b8b9e6a0552e/pkg/presentation/mailboxvalidator/email.go (about) 1 package mailboxvalidator 2 3 import ( 4 "github.com/go-email-validator/go-email-validator/pkg/ev/evmail" 5 "github.com/go-email-validator/go-email-validator/pkg/presentation/converter" 6 "strings" 7 ) 8 9 var emptyString = "" 10 11 // EmailFromString creates evmail.Address from string 12 func EmailFromString(email string) evmail.Address { 13 pos := strings.LastIndexByte(email, '@') 14 15 if pos == -1 || len(email) < 3 { 16 return converter.NewEmailAddress("", email, &emptyString) 17 } 18 19 return converter.NewEmailAddress(email[:pos], email[pos+1:], nil) 20 }