diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-02 01:37:51 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-02 01:37:51 +0000 |
commit | 5efad50005484e4bcd56fd68a46040e3d89b0efe (patch) | |
tree | 9d849941126a5a765fbcb9ecc17f26163858d581 /urls | |
parent | 36e41939772d0441dc023f7b02e96567441b02ec (diff) | |
download | communique-5efad50005484e4bcd56fd68a46040e3d89b0efe.tar.gz |
clean up urls, scheme:host:port now configurable
Diffstat (limited to 'urls')
-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) } |