🎨 Renamed `me` field in Me domain to `id`

This commit is contained in:
Maxim Lebedev 2022-02-08 15:17:03 +05:00
parent 98b6d77dc1
commit e494526389
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 20 additions and 20 deletions

View File

@ -13,14 +13,14 @@ import (
// Me is a URL user identifier. // Me is a URL user identifier.
type Me struct { type Me struct {
me *http.URI id *http.URI
} }
// ParseMe parse string as me URL identifier. // ParseMe parse string as me URL identifier.
//nolint: funlen, cyclop //nolint: funlen, cyclop
func ParseMe(raw string) (*Me, error) { func ParseMe(raw string) (*Me, error) {
me := http.AcquireURI() id := http.AcquireURI()
if err := me.Parse(nil, []byte(raw)); err != nil { if err := id.Parse(nil, []byte(raw)); err != nil {
return nil, NewError( return nil, NewError(
ErrorCodeInvalidRequest, ErrorCodeInvalidRequest,
err.Error(), err.Error(),
@ -29,7 +29,7 @@ func ParseMe(raw string) (*Me, error) {
) )
} }
scheme := string(me.Scheme()) scheme := string(id.Scheme())
if scheme != "http" && scheme != "https" { if scheme != "http" && scheme != "https" {
return nil, NewError( return nil, NewError(
ErrorCodeInvalidRequest, ErrorCodeInvalidRequest,
@ -39,7 +39,7 @@ func ParseMe(raw string) (*Me, error) {
) )
} }
path := string(me.PathOriginal()) path := string(id.PathOriginal())
if path == "" || strings.Contains(path, "/.") || strings.Contains(path, "/..") { if path == "" || strings.Contains(path, "/.") || strings.Contains(path, "/..") {
return nil, NewError( return nil, NewError(
ErrorCodeInvalidRequest, ErrorCodeInvalidRequest,
@ -50,7 +50,7 @@ func ParseMe(raw string) (*Me, error) {
) )
} }
if me.Hash() != nil { if id.Hash() != nil {
return nil, NewError( return nil, NewError(
ErrorCodeInvalidRequest, ErrorCodeInvalidRequest,
"profile URL MUST NOT contain a fragment component", "profile URL MUST NOT contain a fragment component",
@ -59,7 +59,7 @@ func ParseMe(raw string) (*Me, error) {
) )
} }
if me.Username() != nil || me.Password() != nil { if id.Username() != nil || id.Password() != nil {
return nil, NewError( return nil, NewError(
ErrorCodeInvalidRequest, ErrorCodeInvalidRequest,
"profile URL MUST NOT contain a username or password component", "profile URL MUST NOT contain a username or password component",
@ -68,7 +68,7 @@ func ParseMe(raw string) (*Me, error) {
) )
} }
domain := string(me.Host()) domain := string(id.Host())
if domain == "" { if domain == "" {
return nil, NewError( return nil, NewError(
ErrorCodeInvalidRequest, ErrorCodeInvalidRequest,
@ -96,7 +96,7 @@ func ParseMe(raw string) (*Me, error) {
) )
} }
return &Me{me: me}, nil return &Me{id: id}, nil
} }
// TestMe returns valid random generated me for tests. // TestMe returns valid random generated me for tests.
@ -148,41 +148,41 @@ func (m Me) MarshalJSON() ([]byte, error) {
// URI returns copy of parsed me in *fasthttp.URI representation. // URI returns copy of parsed me in *fasthttp.URI representation.
// This copy MUST be released via fasthttp.ReleaseURI. // This copy MUST be released via fasthttp.ReleaseURI.
func (m Me) URI() *http.URI { func (m Me) URI() *http.URI {
if m.me == nil { if m.id == nil {
return nil return nil
} }
u := http.AcquireURI() u := http.AcquireURI()
m.me.CopyTo(u) m.id.CopyTo(u)
return u return u
} }
// URL returns copy of parsed me in *url.URL representation. // URL returns copy of parsed me in *url.URL representation.
func (m Me) URL() *url.URL { func (m Me) URL() *url.URL {
if m.me == nil { if m.id == nil {
return nil return nil
} }
return &url.URL{ return &url.URL{
ForceQuery: false, ForceQuery: false,
Fragment: string(m.me.Hash()), Fragment: string(m.id.Hash()),
Host: string(m.me.Host()), Host: string(m.id.Host()),
Opaque: "", Opaque: "",
Path: string(m.me.Path()), Path: string(m.id.Path()),
RawFragment: "", RawFragment: "",
RawPath: string(m.me.PathOriginal()), RawPath: string(m.id.PathOriginal()),
RawQuery: string(m.me.QueryString()), RawQuery: string(m.id.QueryString()),
Scheme: string(m.me.Scheme()), Scheme: string(m.id.Scheme()),
User: nil, User: nil,
} }
} }
// String returns string representation of me. // String returns string representation of me.
func (m Me) String() string { func (m Me) String() string {
if m.me == nil { if m.id == nil {
return "" return ""
} }
return m.me.String() return m.id.String()
} }