diff options
Diffstat (limited to 'urls/urls.go')
-rw-r--r-- | urls/urls.go | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/urls/urls.go b/urls/urls.go index 91e0b37..6a2025b 100644 --- a/urls/urls.go +++ b/urls/urls.go @@ -3,48 +3,38 @@ package urls import ( "fmt" "net/url" - "path" ) -func UrlInbox(name, domain string) (*url.URL, error) { - u, err := url.Parse(path.Join(domain, "actors", name, "inbox")) - u.Scheme = "https" +func linkTo(name, base string, path ...string) (*url.URL, error) { + u, err := url.JoinPath(base, path...) if err != nil { - return nil, fmt.Errorf("could not build inbox url: %w", err) + return nil, fmt.Errorf("could not build %s url: %w", name, err) } - return u, nil + uri, err := url.Parse(u) + if err != nil { + return nil, fmt.Errorf("could not parse %s url: %w", name, err) + } + return uri, err +} + +func UrlInbox(name, domain string) (*url.URL, error) { + return linkTo("inbox", domain, "actors", name, "inbox") } func UrlOutbox(name, domain string) (*url.URL, error) { - u, err := url.Parse(path.Join(domain, "actors", name, "outbox")) - u.Scheme = "https" - if err != nil { - return nil, fmt.Errorf("could not build outbox url: %w", err) - } - return u, nil + return linkTo("outbox", domain, "actors", name, "outbox") } func UrlActivity(name, domain, id string) (*url.URL, error) { - u, err := url.Parse(path.Join(domain, "actors", name, "activity", id)) - u.Scheme = "https" - if err != nil { - return nil, fmt.Errorf("could not build activity url: %w", err) - } - return u, nil + return linkTo("activity", domain, "actors", name, "activity", id) } func UrlNote(name, domain, id string) (*url.URL, error) { - u, err := url.Parse(path.Join(domain, "actors", name, "activity", id, "note")) - u.Scheme = "https" - if err != nil { - return nil, fmt.Errorf("could not build note url: %w", err) - } - return u, nil + return linkTo("note", domain, "actors", name, "activity", id, "note") } func UrlOutboxPage(name, domain string) (*url.URL, error) { u, err := UrlOutbox(name, domain) - u.Scheme = "https" if err != nil { return nil, fmt.Errorf("could not build outbox page url: %w", err) } |