subhub/handlers/webfinder/address.go

41 lines
770 B
Go
Raw Permalink Normal View History

2019-09-07 14:54:53 +00:00
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
}