From afdf8a014236452e098ab1266c9a9315824f8103 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Mon, 19 Dec 2022 10:41:43 -0500 Subject: url helpers, cgi response format --- urls/urls.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 urls/urls.go (limited to 'urls') diff --git a/urls/urls.go b/urls/urls.go new file mode 100644 index 0000000..5f563a7 --- /dev/null +++ b/urls/urls.go @@ -0,0 +1,34 @@ +package urls + +import ( + "fmt" + "net/url" + "path" +) + +func UrlInbox(name, domain string) (*url.URL, error) { + u, err := url.Parse(path.Join("https://", domain, "actors", name, "inbox")) + if err != nil { + return nil, fmt.Errorf("could not build inbox url: %w", err) + } + return u, nil +} + +func UrlOutbox(name, domain string) (*url.URL, error) { + u, err := url.Parse(path.Join("https://", domain, "actors", name, "outbox")) + if err != nil { + return nil, fmt.Errorf("could not build outbox url: %w", err) + } + return u, nil +} + +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 +} -- cgit v1.2.3