🚚 Renamed NewEmail to ParseEmail
This commit is contained in:
parent
7cb23125c8
commit
2cc1fa02e7
|
@ -3,6 +3,8 @@ package domain
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Email struct {
|
type Email struct {
|
||||||
|
@ -13,9 +15,12 @@ type Email struct {
|
||||||
var ErrEmailInvalid error = Error{
|
var ErrEmailInvalid error = Error{
|
||||||
Code: ErrorCodeInvalidRequest,
|
Code: ErrorCodeInvalidRequest,
|
||||||
Description: "cannot parse email",
|
Description: "cannot parse email",
|
||||||
|
URI: "",
|
||||||
|
State: "",
|
||||||
|
frame: xerrors.Caller(1),
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEmail(src string) (*Email, error) {
|
func ParseEmail(src string) (*Email, error) {
|
||||||
parts := strings.Split(strings.TrimPrefix(src, "mailto:"), "@")
|
parts := strings.Split(strings.TrimPrefix(src, "mailto:"), "@")
|
||||||
if len(parts) != 2 { //nolint: gomnd
|
if len(parts) != 2 { //nolint: gomnd
|
||||||
return nil, ErrEmailInvalid
|
return nil, ErrEmailInvalid
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"source.toby3d.me/website/indieauth/internal/domain"
|
"source.toby3d.me/website/indieauth/internal/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewEmail(t *testing.T) {
|
func TestParseEmail(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
for _, testCase := range []struct {
|
for _, testCase := range []struct {
|
||||||
|
@ -37,7 +37,7 @@ func TestNewEmail(t *testing.T) {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
result, err := domain.NewEmail(testCase.input)
|
result, err := domain.ParseEmail(testCase.input)
|
||||||
if testCase.expError {
|
if testCase.expError {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Nil(t, result)
|
assert.Nil(t, result)
|
||||||
|
|
|
@ -133,7 +133,7 @@ func extractProfile(dst *domain.Profile, src *http.Response) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
e, err := domain.NewEmail(email)
|
e, err := domain.ParseEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue