friend/finger.go

50 lines
1.1 KiB
Go
Raw Normal View History

2022-11-11 07:07:50 +00:00
package main
import (
"fmt"
"strings"
)
type Resource struct {
Subject string `json:"subject"`
Aliases []string `json:"aliases,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
Links []Links `json:"links,omitempty"`
}
type Links struct {
Rel string `json:"rel"`
Type string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
}
type Webfinger struct {
domain string
username string
accountName string
}
func NewWebfinger(username string, domain string, aliases ...string) (*Webfinger, error) {
return &Webfinger{
username: username,
domain: domain,
accountName: fmt.Sprintf("acct:%s@%s", username, domain),
}, nil
}
func (w *Webfinger) FingerResource(name string) (Resource, error) {
if !strings.EqualFold(w.accountName, name) {
return Resource{}, fmt.Errorf("account not found")
}
return Resource{
Subject: w.accountName,
Links: []Links{
{
Rel: "self",
Type: "application/activity+json",
Href: fmt.Sprintf("https://%s/users/%s", w.domain, w.username),
},
},
}, nil
}