2
0
Fork 0

first commit

main
Astra 2024-06-09 00:35:51 +01:00
commit 388ae5a23d
2 changed files with 51 additions and 0 deletions

3
go.mod 100644
View File

@ -0,0 +1,3 @@
module git.zio.sh/astra/gearheads-webfinger
go 1.21.1

48
main.go 100644
View File

@ -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)
}