71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type Actor struct {
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
URL string `json:"url"`
|
|
Name string `json:"name"`
|
|
PreferredUsername string `json:"preferredUsername,omitempty"`
|
|
Summary string `json:"summary,omitempty"`
|
|
|
|
PublicKey PublicKey `json:"publicKey,omitempty"`
|
|
|
|
Inbox string `json:"inbox,omitempty"`
|
|
Outbox string `json:"outbox,omitempty"`
|
|
Followers string `json:"followers,omitempty"`
|
|
Following string `json:"following,omitempty"`
|
|
|
|
Icon *Link `json:"icon,omitempty"`
|
|
Image *Link `json:"image,omitempty"`
|
|
|
|
Endpoints map[string]string `json:"endpoints,omitempty"`
|
|
}
|
|
|
|
type Link struct {
|
|
Type string `json:"type"`
|
|
MediaType string `json:"mediaType"`
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
type PublicKey struct {
|
|
ID string `json:"id"`
|
|
Owner string `json:"owner"`
|
|
PublicKeyPem string `json:"publicKeyPem"`
|
|
}
|
|
|
|
type ProfileProvider struct {
|
|
username string
|
|
domain string
|
|
}
|
|
|
|
func NewProfileProvider(username, domain string) (*ProfileProvider, error) {
|
|
return &ProfileProvider{
|
|
username: username,
|
|
domain: domain,
|
|
}, nil
|
|
}
|
|
|
|
func (pp *ProfileProvider) Get() (*Actor, error) {
|
|
userRoot := fmt.Sprintf("https://%s/users/%s", pp.domain, pp.username)
|
|
return &Actor{
|
|
ID: userRoot,
|
|
Type: "Person",
|
|
URL: fmt.Sprintf("https://%s/@%s", pp.domain, pp.username),
|
|
Name: pp.username,
|
|
Inbox: userRoot + "/inbox",
|
|
Outbox: userRoot + "/outbox",
|
|
Followers: userRoot + "/followers",
|
|
Following: userRoot + "/following",
|
|
Endpoints: map[string]string{
|
|
"sharedInbox": fmt.Sprintf("https://%s/inbox", pp.domain),
|
|
},
|
|
PublicKey: PublicKey{
|
|
ID: userRoot + "#main-key",
|
|
Owner: userRoot,
|
|
PublicKeyPem: "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----",
|
|
},
|
|
}, nil
|
|
}
|