41 lines
770 B
Go
41 lines
770 B
Go
|
package webfinder
|
||
|
|
||
|
import (
|
||
|
"git.macaw.me/inhosin/subhub/handlers"
|
||
|
"net/mail"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func newBadAddressError(address string) *badAddressError {
|
||
|
return &badAddressError{address: address}
|
||
|
}
|
||
|
|
||
|
func slugOf(address string) string {
|
||
|
fragment := strings.Split(address, "@")
|
||
|
return fragment[0]
|
||
|
}
|
||
|
|
||
|
func atAddress(address string) (*Resource, error) {
|
||
|
// foo@bar.org => foo
|
||
|
parser := mail.AddressParser{}
|
||
|
_, err := parser.Parse(address)
|
||
|
if err != nil {
|
||
|
return nil, newBadAddressError(address)
|
||
|
}
|
||
|
|
||
|
// foo@bar.org => foo
|
||
|
slug := slugOf(address)
|
||
|
domain := handlers.GetFullHostName()
|
||
|
|
||
|
return &Resource{
|
||
|
Subject: address,
|
||
|
Links: []Link{
|
||
|
{
|
||
|
Rel: "self",
|
||
|
Type: "application/activity+json",
|
||
|
HRef: domain + "/api/group/" + slug,
|
||
|
},
|
||
|
},
|
||
|
}, nil
|
||
|
}
|