go-macaron/macaron

Middleware exception

shawnye opened this issue · 3 comments

I just write a middleware toy:

var router *macaron.Macaron

func init(){
   router = macaron.Classic()
   router.Use(session.Sessioner()) 

   router.Use(PresetCtx)
   router.Use(pongo2.Pongoer())

	router.Route("/goto_login", "POST,GET", func(ctx *macaron.Context, sess session.Store) {
		// Use PresetCtx
		// ctx.Data["AppName"] = GetAppName(sess)
		// ctx.Data["IP"] = ctx.RemoteAddr
		ctx.HTML(200, "sys/login")
	})

	log.Fatal(http.ListenAndServe(":8080", router))

}

func PresetCtx() macaron.Handler {
	fmt.Println("PresetCtx")

	return func( /*req *http.Request,*/ ctx *macaron.Context /*, sess session.Store*/) {
		fmt.Println("$$$$before a request")

		// ctx.Data["AppName"] = GetAppName(sess)
		ctx.Data["IP"] = ctx.RemoteAddr

		ctx.Next()
	}
}

when server started, it just show following message on the page, what's wrong with it , thank you!

<func(*macaron.Context) Value>

Thanks @humaidq ! Yes, that's the correct answer :)

It worked, thanks all of you!