2
0
Fork 0
webfinger/main.go

51 lines
1.3 KiB
Go
Raw Normal View History

2024-06-09 01:35:51 +02:00
package main
import (
"fmt"
"net/http"
)
var redirects map[string][]string
func HandleWebfinger(w http.ResponseWriter, req *http.Request) {
olduser := req.URL.Query().Get("resource")[5:]
newuser, ok := redirects[olduser]
if !ok {
w.WriteHeader(404)
return
}
s := `{
"subject": "acct:%[1]s@%[2]s",
"aliases": [
"https://%[2]s/@%[1]s",
"https://%[2]s/users/%[1]s"
],
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
"href": "https://%[2]s/@%[1]s"
},
{
"rel": "self",
"type": "application/activity+json",
"href": "https://%[2]s/users/%[1]s"
}
]
}`
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, fmt.Sprintf(s, newuser[0], newuser[1]))
}
func main() {
redirects = make(map[string][]string)
redirects["astra@gearheads.social"] = []string{"astra", "ap.zio.sh"}
2024-06-17 21:03:36 +02:00
redirects["ducky@gearheads.social"] = []string{"ducky", "ap.zio.sh"}
redirects["creativeicing@gearheads.social"] = []string{"CreativeIcing", "rubber.social"}
redirects["gearbound@gearheads.social"] = []string{"gearbound", "rubber.social"}
2024-06-09 01:35:51 +02:00
http.HandleFunc("/.well-known/webfinger", HandleWebfinger)
http.ListenAndServe(":8888", nil)
}