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"} 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"} http.HandleFunc("/.well-known/webfinger", HandleWebfinger) http.ListenAndServe(":8888", nil) }