Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic... #39

Closed
zquestz opened this issue May 19, 2016 · 2 comments · May be fixed by #48
Closed

Panic... #39

zquestz opened this issue May 19, 2016 · 2 comments · May be fixed by #48

Comments

@zquestz
Copy link

zquestz commented May 19, 2016

So was giving this library a try, but I can't seem to get it working. Wrote a tiny sample app just to make sure there was nothing special in my code.

package main

import (
    "log"
    "net/http"

    "github.com/braintree/manners"
)

func main() {
    http.Handle("/hello", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello\n"))
    }))
    log.Fatal(manners.ListenAndServe(":8080", nil))
}

This panics and returns the following stack trace.

2016/05/19 16:49:55 http: panic serving [::1]:39150: runtime error: invalid memory address or nil pointer dereference
goroutine 18 [running]:
net/http.(*conn).serve.func1(0xc8200ce000)
    /usr/lib/go/src/net/http/server.go:1389 +0xc1
panic(0x711720, 0xc82000a230)
    /usr/lib/go/src/runtime/panic.go:443 +0x4e9
github.com/braintree/manners.(*gracefulHandler).ServeHTTP(0xc8200babe0, 0x7f381b775130, 0xc8200e2000, 0xc8200de000)
    /home/quest/go/src/github.com/braintree/manners/server.go:277 +0x78
net/http.serverHandler.ServeHTTP(0xc82007a080, 0x7f381b775130, 0xc8200e2000, 0xc8200de000)
    /usr/lib/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc8200ce000)
    /usr/lib/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
    /usr/lib/go/src/net/http/server.go:2137 +0x44e
2016/05/19 16:49:57 http: panic serving [::1]:39156: runtime error: invalid memory address or nil pointer dereference

Am I doing something wrong? The docs don't wrap the Handle passed function with http.HandlerFunc, but that is required for it to compile. Has this been tested against Go 1.6?

@zquestz
Copy link
Author

zquestz commented May 19, 2016

NOTE: this does work if I pass the handler directly into the ListenAndServe method. Just not if I use http.Handle.

@ghost
Copy link

ghost commented May 21, 2016

I think the examples floating around for Manners might be a bit mixed up. It seems to imply you can setup the net/http library handlers as per usual and then fire manners ListenAndServe() to start the server.

It actually doesn't go looking for the default mux if you use Handle() or HandleFunc() against the http library. Something along the lines of the following seems to work if you want to do it this way -

    http.HandleFunc("/doSomething/", doSomething)
    manners.ListenAndServe(":8080", http.DefaultServeMux)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant