jeudi 30 mars 2017

Golang route not working

I just started to get into golang and as I plan to host at least two websites, I chose to use Mux to display different routes by "filtering" domains. Whenever I try to access my main route, it just gives me an 404 error. (Also, the fact that the "www" part is absent is perfectly normal. I don't type that to access the site).

But if I launch the server as a file server, I can access my files, so the server in itself is working I guess

func redirect(w http.ResponseWriter, req *http.Request) {
    target := "https://" + req.Host + req.URL.Path
    http.Redirect(w, req, target,
        http.StatusTemporaryRedirect)
}

func main() {
    go http.ListenAndServe(":80", http.HandlerFunc(redirect)) // Redirection

    // Serveur sécurisé

    r := mux.NewRouter()
    r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("/root/go/src/web/static/"))))
    s := r.Host("echecderi.me").Subrouter()
    s.HandleFunc("/", indexEchec)

    http.ListenAndServeTLS(":443", "domain-crt.pem", "domain-key.pem", nil)
}

func indexEchec(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "<h1>Echec de rime</h1> </br> <img src=\"/static/echecderime/echec.gif\">")
}




Aucun commentaire:

Enregistrer un commentaire