🚚 Renamed NewMe to ParseMe

This commit is contained in:
Maxim Lebedev 2022-01-29 19:54:37 +05:00
parent c31d47d5ae
commit 7ce8335212
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
8 changed files with 13 additions and 13 deletions

View File

@ -19,7 +19,7 @@ type Me struct {
} }
//nolint: funlen //nolint: funlen
func NewMe(raw string) (*Me, error) { func ParseMe(raw string) (*Me, error) {
me := http.AcquireURI() me := http.AcquireURI()
if err := me.Parse(nil, []byte(raw)); err != nil { if err := me.Parse(nil, []byte(raw)); err != nil {
return nil, Error{ return nil, Error{
@ -104,7 +104,7 @@ func NewMe(raw string) (*Me, error) {
func TestMe(tb testing.TB, src string) *Me { func TestMe(tb testing.TB, src string) *Me {
tb.Helper() tb.Helper()
me, err := NewMe(src) me, err := ParseMe(src)
require.NoError(tb, err) require.NoError(tb, err)
return me return me
@ -112,7 +112,7 @@ func TestMe(tb testing.TB, src string) *Me {
// UnmarshalForm parses the value of the form key into the Me domain. // UnmarshalForm parses the value of the form key into the Me domain.
func (m *Me) UnmarshalForm(v []byte) error { func (m *Me) UnmarshalForm(v []byte) error {
me, err := NewMe(string(v)) me, err := ParseMe(string(v))
if err != nil { if err != nil {
return fmt.Errorf("UnmarshalForm: %w", err) return fmt.Errorf("UnmarshalForm: %w", err)
} }
@ -128,7 +128,7 @@ func (m *Me) UnmarshalJSON(v []byte) error {
return err return err
} }
me, err := NewMe(src) me, err := ParseMe(src)
if err != nil { if err != nil {
return fmt.Errorf("UnmarshalForm: %w", err) return fmt.Errorf("UnmarshalForm: %w", err)
} }

View File

@ -10,7 +10,7 @@ import (
) )
//nolint: funlen //nolint: funlen
func TestNewMe(t *testing.T) { func TestParseMe(t *testing.T) {
t.Parallel() t.Parallel()
for _, testCase := range []struct { for _, testCase := range []struct {
@ -63,7 +63,7 @@ func TestNewMe(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.NewMe(testCase.input) result, err := domain.ParseMe(testCase.input)
if testCase.isValid { if testCase.isValid {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, testCase.input, result.String()) assert.Equal(t, testCase.input, result.String())

View File

@ -130,7 +130,7 @@ func (t *Session) Populate(dst *domain.Session) {
dst.Code = t.Code dst.Code = t.Code
dst.CodeChallenge = t.CodeChallenge dst.CodeChallenge = t.CodeChallenge
dst.CodeChallengeMethod, _ = domain.ParseCodeChallengeMethod(t.CodeChallengeMethod) dst.CodeChallengeMethod, _ = domain.ParseCodeChallengeMethod(t.CodeChallengeMethod)
dst.Me, _ = domain.NewMe(t.Me) dst.Me, _ = domain.ParseMe(t.Me)
dst.RedirectURI, _ = domain.NewURL(t.RedirectURI) dst.RedirectURI, _ = domain.NewURL(t.RedirectURI)
for _, scope := range strings.Fields(t.Scope) { for _, scope := range strings.Fields(t.Scope) {

View File

@ -23,7 +23,7 @@ import (
type ( type (
GenerateRequest struct { GenerateRequest struct {
// The access token should be used when acting on behalf of this URL. // The access token should be used when acting on behalf of this URL.
Subject *domain.URL `form:"subject"` Subject *domain.Me `form:"subject"`
// The access token will work at this URL. // The access token will work at this URL.
Resource *domain.URL `form:"resource"` Resource *domain.URL `form:"resource"`
@ -34,7 +34,7 @@ type (
Ticket string `form:"ticket"` Ticket string `form:"ticket"`
// The access token should be used when acting on behalf of this URL. // The access token should be used when acting on behalf of this URL.
Subject *domain.URL `form:"subject"` Subject *domain.Me `form:"subject"`
// The access token will work at this URL. // The access token will work at this URL.
Resource *domain.URL `form:"resource"` Resource *domain.URL `form:"resource"`

View File

@ -114,6 +114,6 @@ func NewTicket(src *domain.Ticket) *Ticket {
func (t *Ticket) Populate(dst *domain.Ticket) { func (t *Ticket) Populate(dst *domain.Ticket) {
dst.Ticket = t.Ticket dst.Ticket = t.Ticket
dst.Subject, _ = domain.NewURL(t.Subject) dst.Subject, _ = domain.ParseMe(t.Subject)
dst.Resource, _ = domain.NewURL(t.Resource) dst.Resource, _ = domain.NewURL(t.Resource)
} }

View File

@ -91,7 +91,7 @@ func NewToken(src *domain.Token) *Token {
func (t *Token) Populate(dst *domain.Token) { func (t *Token) Populate(dst *domain.Token) {
dst.AccessToken = t.AccessToken dst.AccessToken = t.AccessToken
dst.ClientID, _ = domain.ParseClientID(t.ClientID) dst.ClientID, _ = domain.ParseClientID(t.ClientID)
dst.Me, _ = domain.NewMe(t.Me) dst.Me, _ = domain.ParseMe(t.Me)
dst.Scope = make(domain.Scopes, 0) dst.Scope = make(domain.Scopes, 0)
for _, scope := range strings.Fields(t.Scope) { for _, scope := range strings.Fields(t.Scope) {

View File

@ -107,7 +107,7 @@ func (useCase *tokenUseCase) Verify(ctx context.Context, accessToken string) (*d
AccessToken: accessToken, AccessToken: accessToken,
} }
result.ClientID, _ = domain.ParseClientID(t.Issuer()) result.ClientID, _ = domain.ParseClientID(t.Issuer())
result.Me, _ = domain.NewMe(t.Subject()) result.Me, _ = domain.ParseMe(t.Subject())
if scope, ok := t.Get("scope"); ok { if scope, ok := t.Get("scope"); ok {
result.Scope, _ = scope.(domain.Scopes) result.Scope, _ = scope.(domain.Scopes)

View File

@ -53,7 +53,7 @@ func (repo *httpUserRepository) Get(ctx context.Context, me *domain.Me) (*domain
} }
// TODO(toby3d): handle error here? // TODO(toby3d): handle error here?
resolvedMe, _ := domain.NewMe(string(resp.Header.Peek(http.HeaderLocation))) resolvedMe, _ := domain.ParseMe(string(resp.Header.Peek(http.HeaderLocation)))
u := &domain.User{ u := &domain.User{
Me: resolvedMe, Me: resolvedMe,
Profile: &domain.Profile{ Profile: &domain.Profile{