🚚 Renamed NewURL to ParseURL

This commit is contained in:
Maxim Lebedev 2022-01-29 19:57:54 +05:00
parent 7ce8335212
commit f6174c67e0
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
6 changed files with 16 additions and 18 deletions

View File

@ -89,14 +89,14 @@ func extract(dst *domain.Client, src *http.Response) {
var u *domain.URL
switch l := logo.(type) {
case string:
u, err = domain.NewURL(l)
u, err = domain.ParseURL(l)
case map[string]string:
value, ok := l["value"]
if !ok {
continue
}
u, err = domain.NewURL(value)
u, err = domain.ParseURL(value)
}
if err != nil {
@ -116,7 +116,7 @@ func extract(dst *domain.Client, src *http.Response) {
continue
}
u, err := domain.NewURL(l)
u, err := domain.ParseURL(l)
if err != nil {
continue
}

View File

@ -12,15 +12,13 @@ type URL struct {
*http.URI
}
func NewURL(src string) (*URL, error) {
u := &URL{
URI: http.AcquireURI(),
}
if err := u.URI.Parse(nil, []byte(src)); err != nil {
func ParseURL(src string) (*URL, error) {
u := http.AcquireURI()
if err := u.Parse(nil, []byte(src)); err != nil {
return nil, err
}
return u, nil
return &URL{URI: u}, nil
}
func TestURL(tb testing.TB, src string) *URL {
@ -35,7 +33,7 @@ func TestURL(tb testing.TB, src string) *URL {
}
func (u *URL) UnmarshalForm(v []byte) error {
url, err := NewURL(string(v))
url, err := ParseURL(string(v))
if err != nil {
return err
}
@ -51,7 +49,7 @@ func (u *URL) UnmarshalJSON(v []byte) error {
return err
}
url, err := NewURL(src)
url, err := ParseURL(src)
if err != nil {
return err
}

View File

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

View File

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

View File

@ -147,7 +147,7 @@ func extractProfile(dst *domain.Profile, src *http.Response) {
continue
}
u, err := domain.NewURL(url)
u, err := domain.ParseURL(url)
if err != nil {
continue
}
@ -161,7 +161,7 @@ func extractProfile(dst *domain.Profile, src *http.Response) {
continue
}
p, err := domain.NewURL(photo)
p, err := domain.ParseURL(photo)
if err != nil {
continue
}

View File

@ -106,17 +106,17 @@ func init() {
logger.Fatalln("fail to read config:", err)
}
url, err := domain.NewURL(rootURL)
url, err := domain.ParseURL(rootURL)
if err != nil {
logger.Fatalln("cannot parse root URL as client URL:", err)
}
logo, err := domain.NewURL(rootURL + config.Server.StaticURLPrefix + "/icon.svg")
logo, err := domain.ParseURL(rootURL + config.Server.StaticURLPrefix + "/icon.svg")
if err != nil {
logger.Fatalln("cannot parse root URL as client URL:", err)
}
redirectURI, err := domain.NewURL(rootURL + "/callback")
redirectURI, err := domain.ParseURL(rootURL + "/callback")
if err != nil {
logger.Fatalln("cannot parse root URL as client URL:", err)
}