package registry import ( "fmt" "path" "git.capotej.com/capotej/communique/config" "git.capotej.com/capotej/communique/resources" ) 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) 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) *resources.WebfingerResource { handler, ok := r.handlerMap[fqdn] if !ok { return nil } rs := resources.WebfingerResource{ Subject: fmt.Sprintf("acct:%s@%s", handler.handlerCfg.Name, r.cfg.Domain), Aliases: []string{}, Links: []resources.Link{{ Rel: "self", Href: path.Join("https://", r.cfg.Domain, "actors", handler.handlerCfg.Name), Type: "application/activity+json", }}, } return &rs }