package handler import ( _ "embed" "net/http" ) //go:embed static/index.html var indexPage string func New(matrixHostname, matrixBaseURL string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.NotFound(w, r) return } switch r.URL.Path { case "/.well-known/matrix/server": w.Header().Add("content-type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte(`{"m.server": "` + matrixHostname + `"}`)) case "/.well-known/matrix/client": w.Header().Add("content-type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte(`{"m.homeserver": {"base_url": "` + matrixBaseURL + `"}}`)) default: w.Header().Add("content-type", "text/html") w.WriteHeader(http.StatusOK) w.Write([]byte(indexPage)) } } }