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 when dumping a gorilla named route #31

Open
fgm opened this issue Sep 13, 2019 · 0 comments
Open

Panic when dumping a gorilla named route #31

fgm opened this issue Sep 13, 2019 · 0 comments

Comments

@fgm
Copy link

fgm commented Sep 13, 2019

Seems similar to #18 but still happens with current version:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gorilla/mux"
	"github.com/sanity-io/litter"
)

func main() {
	r := mux.NewRouter()

	r.HandleFunc(`/foo`, AnyHandler).Name("named")
	r.HandleFunc("/", AnyHandler).Name("front")

	srv := &http.Server{
		Handler: r,
		Addr:    "127.0.0.1:8000",
	}

	log.Fatal(srv.ListenAndServe())
}

func AnyHandler(w http.ResponseWriter, r *http.Request) {
	route := mux.CurrentRoute(r)
	litter.Config.HidePrivateFields = false
	fmt.Fprintln(w, route.GetName())
	defer func() {
		p := recover()
		if p != nil {
			fmt.Printf("Recovered: %#v\n", p)
		}
	}()
	litter.Sdump(route)
}
  • Navigate to either / or /foo
  • Panics with: "reflect.Value.Interface: cannot return value obtained from unexported field or method"
  • Does not panic if only one of the routes is handled
  • Does not panic if either of the routes is not named
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

No branches or pull requests

1 participant