webfinger.go 957 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package apmodels
  2. import (
  3. "fmt"
  4. )
  5. // WebfingerResponse represents a Webfinger response.
  6. type WebfingerResponse struct {
  7. Aliases []string `json:"aliases"`
  8. Subject string `json:"subject"`
  9. Links []Link `json:"links"`
  10. }
  11. // Link represents a Webfinger response Link entity.
  12. type Link struct {
  13. Rel string `json:"rel"`
  14. Type string `json:"type"`
  15. Href string `json:"href"`
  16. }
  17. // MakeWebfingerResponse will create a new Webfinger response.
  18. func MakeWebfingerResponse(account string, inbox string, host string) WebfingerResponse {
  19. accountIRI := MakeLocalIRIForAccount(account)
  20. return WebfingerResponse{
  21. Subject: fmt.Sprintf("acct:%s@%s", account, host),
  22. Aliases: []string{
  23. accountIRI.String(),
  24. },
  25. Links: []Link{
  26. {
  27. Rel: "self",
  28. Type: "application/activity+json",
  29. Href: accountIRI.String(),
  30. },
  31. {
  32. Rel: "http://webfinger.net/rel/profile-page",
  33. Type: "text/html",
  34. Href: accountIRI.String(),
  35. },
  36. },
  37. }
  38. }