first commit
commit
388ae5a23d
|
@ -0,0 +1,48 @@
|
|||
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["ducky@gearheads.social"] = []string{"ducky", "ap.zio.sh"}
|
||||
redirects["astra@gearheads.social"] = []string{"astra", "ap.zio.sh"}
|
||||
|
||||
http.HandleFunc("/.well-known/webfinger", HandleWebfinger)
|
||||
http.ListenAndServe(":8888", nil)
|
||||
}
|
Loading…
Reference in New Issue