diff options
-rw-r--r-- | sample-config.toml | 2 | ||||
-rw-r--r-- | urls/urls.go | 40 |
2 files changed, 16 insertions, 26 deletions
diff --git a/sample-config.toml b/sample-config.toml index 7cd02f7..293a525 100644 --- a/sample-config.toml +++ b/sample-config.toml @@ -1,4 +1,4 @@ -domain = "activitybub.xyz" +domain = "http://localhost:8080" dbPath = "bub.db" # [[handlers]] 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) } |