package urls import ( "fmt" "net/url" ) 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 %s url: %w", name, err) } 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) { return linkTo("outbox", domain, "actors", name, "outbox") } func UrlActivity(name, domain, id string) (*url.URL, error) { return linkTo("activity", domain, "actors", name, "activity", id) } func UrlNote(name, domain, id string) (*url.URL, error) { return linkTo("note", domain, "actors", name, "activity", id, "note") } func UrlOutboxPage(name, domain string) (*url.URL, error) { u, err := UrlOutbox(name, domain) if err != nil { return nil, fmt.Errorf("could not build outbox page url: %w", err) } q := u.Query() q.Set("page", "true") u.RawQuery = q.Encode() return u, nil }