46 lines
913 B
Go
46 lines
913 B
Go
package webfinder
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func Get(c *gin.Context) {
|
|
res := c.Query("resource")
|
|
if res == "" {
|
|
c.String(http.StatusBadRequest, "Missing 'resouce' query parameter in webfinger")
|
|
return
|
|
}
|
|
|
|
address, err := getAddress(res)
|
|
if err != nil {
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
}
|
|
// TODO find group???
|
|
actor, err := atAddress(address)
|
|
if err != nil {
|
|
if _, ok := err.(*badAddressError); ok {
|
|
c.String(http.StatusBadRequest, "Incorrect address format")
|
|
return
|
|
}
|
|
|
|
c.String(http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
if actor == nil {
|
|
c.String(http.StatusBadRequest, "Account not found")
|
|
}
|
|
|
|
c.JSON(http.StatusOK, actor)
|
|
}
|
|
|
|
func getAddress(res string) (string, error) {
|
|
args := strings.Split(res, ":")
|
|
if args[0] != "acct" {
|
|
return "", errors.New("Resource didn`t start with acct")
|
|
}
|
|
return args[1], nil
|
|
}
|