🚚 Renamed NewEmail to ParseEmail

This commit is contained in:
Maxim Lebedev 2022-01-29 19:43:00 +05:00
parent 7cb23125c8
commit 2cc1fa02e7
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
3 changed files with 9 additions and 4 deletions

View File

@ -3,6 +3,8 @@ package domain
import (
"strings"
"testing"
"golang.org/x/xerrors"
)
type Email struct {
@ -13,9 +15,12 @@ type Email struct {
var ErrEmailInvalid error = Error{
Code: ErrorCodeInvalidRequest,
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:"), "@")
if len(parts) != 2 { //nolint: gomnd
return nil, ErrEmailInvalid

View File

@ -8,7 +8,7 @@ import (
"source.toby3d.me/website/indieauth/internal/domain"
)
func TestNewEmail(t *testing.T) {
func TestParseEmail(t *testing.T) {
t.Parallel()
for _, testCase := range []struct {
@ -37,7 +37,7 @@ func TestNewEmail(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
result, err := domain.NewEmail(testCase.input)
result, err := domain.ParseEmail(testCase.input)
if testCase.expError {
assert.Error(t, err)
assert.Nil(t, result)

View File

@ -133,7 +133,7 @@ func extractProfile(dst *domain.Profile, src *http.Response) {
continue
}
e, err := domain.NewEmail(email)
e, err := domain.ParseEmail(email)
if err != nil {
continue
}