aboutsummaryrefslogtreecommitdiff
path: root/registry/registry.go
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2022-12-17 21:19:49 +0000
committerJulio Capote <jcapote@gmail.com>2022-12-17 21:19:49 +0000
commit7baee5b892afcddb72a575282c6c8983d477ed44 (patch)
tree1dbde5fe9ab9d3d2f46090f0c72fc0246c410879 /registry/registry.go
parent2585e05af116cb95d2d2c36b096345c2b982e39c (diff)
downloadcommunique-7baee5b892afcddb72a575282c6c8983d477ed44.tar.gz
introduce concept of registry, start of webfinger impl
Diffstat (limited to 'registry/registry.go')
-rw-r--r--registry/registry.go42
1 files changed, 42 insertions, 0 deletions
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 &reg
+}
+
+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
+}