1

I try render a template:

func main() {
http.HandleFunc("/", index)
http.HandleFunc("/login", login)
err := fcgi.Serve(nil, http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
   w.Header().Set("Content-type", "text/html")
   t, _ := template.ParseFiles("404.html")
   t.Execute(w, &page{Title: "not work"})
}

But when I open every page, even site.com/login, I see 404. Where can I find the problem?

1 Answer 1

2

fcgi package documentation explains

[...] If handler [second argument of fcgi.Serve] is nil, http.DefaultServeMux is used.

In order to make use of functions registered with http.HandleFunc in http.DefaultServeMux you should not pass second argument to Serve function otherwise the handler function will serve all requests.

func main() {
    http.HandleFunc("/", index)
    http.HandleFunc("/login", login)
    err := fcgi.Serve(nil, nil)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.