func MapEncoder(c martini.Context, w http.ResponseWriter, r *http.Request) {
	// Get the format extension
	matches := rxExt.FindStringSubmatch(r.URL.Path)
	ft := ".json"
	if len(matches) > 1 {
		// Rewrite the URL without the format extension
		l := len(r.URL.Path) - len(matches[1])
		if strings.HasSuffix(r.URL.Path, "/") {
			l--
		}
		r.URL.Path = r.URL.Path[:l]
		ft = matches[1]
	}
	// Inject the requested encoder
	switch ft {
	case ".xml":
		c.MapTo(routes.XmlEncoder{}, (*routes.Encoder)(nil))
		w.Header().Set("Content-Type", "application/xml")
	case ".text":
		c.MapTo(routes.TextEncoder{}, (*routes.Encoder)(nil))
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	default:
		c.MapTo(routes.JsonEncoder{}, (*routes.Encoder)(nil))
		w.Header().Set("Content-Type", "application/json")
	}
}
// MapEncoder intercepts the request's URL, detects the requested format,
// and injects the correct encoder dependency for this request. It rewrites
// the URL to remove the format extension, so that routes can be defined
// without it.
MapEncoder intercepts the request's URL, detects the requested format,
and injects the correct encoder dependency for this request. It rewrites
the URL to remove the format extension, so that routes can be defined
without it.
// MapEncoder intercepts the request ' s URL detects the requested format // and injects the correct encoder dependency for this request . It rewrites // the URL to remove the format extension so that routes can be defined // without it .
func MapEncoder(c martini.Context, w http.ResponseWriter, r *http.Request) {
	matches := rxExt.FindStringSubmatch(r.URL.Path)
	ft := ".json"
	if len(matches) > 1 {
		l := len(r.URL.Path) - len(matches[1])
		if strings.HasSuffix(r.URL.Path, "/") {
			l--
		}
		r.URL.Path = r.URL.Path[:l]
		ft = matches[1]
	}
	switch ft {
	case ".xml":
		c.MapTo(routes.XmlEncoder{}, (*routes.Encoder)(nil))
		w.Header().Set("Content-Type", "application/xml")
	case ".text":
		c.MapTo(routes.TextEncoder{}, (*routes.Encoder)(nil))
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	default:
		c.MapTo(routes.JsonEncoder{}, (*routes.Encoder)(nil))
		w.Header().Set("Content-Type", "application/json")
	}
}
func MapEncoder ( c martini . Context , w http . ResponseWriter , r * http . Request ) { matches := rxExt . FindStringSubmatch ( r . URL . Path ) ft := " " if len ( matches ) > 1 { l := len ( r . URL . Path ) - len ( matches [ 1 ] ) if strings . HasSuffix ( r . URL . Path , " " ) { l -- } r . URL . Path = r . URL . Path [ : l ] ft = matches [ 1 ] } switch ft { case " " : c . MapTo ( routes . XmlEncoder { } , ( * routes . Encoder ) ( nil ) ) w . Header ( ) . Set ( " " , " " ) case " " : c . MapTo ( routes . TextEncoder { } , ( * routes . Encoder ) ( nil ) ) w . Header ( ) . Set ( " " , " " ) default : c . MapTo ( routes . JsonEncoder { } , ( * routes . Encoder ) ( nil ) ) w . Header ( ) . Set ( " " , " " ) } }
MapEncoder intercepts the request's URL, detects the requested format,
and injects the correct encoder dependency for this request.
MapEncoder intercepts the request ' s URL detects the requested format and injects the correct encoder dependency for this request .
// Get the format extension // Rewrite the URL without the format extension // Inject the requested encoder