From 7baee5b892afcddb72a575282c6c8983d477ed44 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sat, 17 Dec 2022 16:19:49 -0500 Subject: introduce concept of registry, start of webfinger impl --- registry/registry.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 registry/registry.go (limited to 'registry') diff --git a/registry/registry.go b/registry/registry.go new file mode 100644 index 0000000..04c4565 --- /dev/null +++ b/registry/registry.go @@ -0,0 +1,42 @@ +package registry + +import ( + "fmt" + + "git.capotej.com/capotej/communique/config" + "git.capotej.com/capotej/communique/webfinger" +) + +type Handler struct { + handlerCfg config.Handler +} + +type Registry struct { + cfg config.Config + handlerMap map[string]Handler +} + +func NewRegistry(cfg config.Config) *Registry { + reg := Registry{cfg: cfg} + reg.handlerMap = make(map[string]Handler) + for _, v := range cfg.Handlers { + fqdn := fmt.Sprintf("acct:%s@%s", v.Name, cfg.Domain) + reg.handlerMap[fqdn] = Handler{handlerCfg: v} + } + return ® +} + +func (r *Registry) LookupResource(name string) *webfinger.Resource { + handler, ok := r.handlerMap[name] + if !ok { + return nil + } + rs := webfinger.Resource{ + Subject: fmt.Sprintf("acct:%s@%s", handler.handlerCfg.Name, "activitybub.xyz"), + Aliases: []string{}, + Links: []webfinger.Link{{ + Rel: "asd", + }}, + } + return &rs +} -- cgit v1.2.3