blob: 04c45658e34dee496ddafe5d4dd9ada298588090 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
}
|