From 0e1e52b457a452e1cf4f852b88288cb324165f54 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sat, 17 Dec 2022 16:35:26 -0500 Subject: refactor webfinger package into resources --- registry/registry.go | 18 +++++++++++------- resources/webfinger.go | 13 +++++++++++++ webfinger/webfinger.go | 13 ------------- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 resources/webfinger.go delete mode 100644 webfinger/webfinger.go diff --git a/registry/registry.go b/registry/registry.go index fc0e9d9..438f821 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -2,9 +2,10 @@ package registry import ( "fmt" + "path" "git.capotej.com/capotej/communique/config" - "git.capotej.com/capotej/communique/webfinger" + "git.capotej.com/capotej/communique/resources" ) type Handler struct { @@ -26,22 +27,25 @@ func NewRegistry(cfg config.Config) *Registry { return ® } -func (r *Registry) LookupByName(name string) *webfinger.Resource { +func (r *Registry) LookupByName(name string) *resources.WebfingerResource { fqdn := fmt.Sprintf("acct:%s@%s", name, r.cfg.Domain) return r.LookupResource(fqdn) } -func (r *Registry) LookupResource(fqdn string) *webfinger.Resource { +func (r *Registry) LookupResource(fqdn string) *resources.WebfingerResource { handler, ok := r.handlerMap[fqdn] if !ok { return nil } - rs := webfinger.Resource{ - Subject: fmt.Sprintf("acct:%s@%s", handler.handlerCfg.Name, "activitybub.xyz"), + rs := resources.WebfingerResource{ + Subject: fmt.Sprintf("acct:%s@%s", handler.handlerCfg.Name, r.cfg.Domain), Aliases: []string{}, - Links: []webfinger.Link{{ - Rel: "asd", + Links: []resources.Link{{ + Rel: "self", + Href: path.Join("https://", r.cfg.Domain, "actors", handler.handlerCfg.Name), + Type: "application/activity+json", }}, } return &rs + } diff --git a/resources/webfinger.go b/resources/webfinger.go new file mode 100644 index 0000000..d936519 --- /dev/null +++ b/resources/webfinger.go @@ -0,0 +1,13 @@ +package resources + +type Link struct { + Rel string `json:"rel"` + Type string `json:"type"` + Href string `json:"href"` +} + +type WebfingerResource struct { + Subject string `json:"subject"` + Aliases []string `json:"aliases"` + Links []Link `json:"links"` +} diff --git a/webfinger/webfinger.go b/webfinger/webfinger.go deleted file mode 100644 index 8e43dd2..0000000 --- a/webfinger/webfinger.go +++ /dev/null @@ -1,13 +0,0 @@ -package webfinger - -type Link struct { - Rel string `json:"rel"` - Type string `json:"type"` - Href string `json:"href"` -} - -type Resource struct { - Subject string `json:"subject"` - Aliases []string `json:"aliases"` - Links []Link `json:"links"` -} -- cgit v1.2.3