func (srv *Server) HandleJSON(handle JSONHandler) httprouter.Handle {
	return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
		ctx := req.Context()
		val, err := handle(Params{
			Response: headerOnlyResponseWriter{w.Header()},
			Request:  req,
			PathVar:  p,
			Context:  ctx,
		})
		if err == nil {
			if err = WriteJSON(w, http.StatusOK, val); err == nil {
				return
			}
		}
		srv.WriteError(ctx, w, err)
	}
}
// HandleJSON returns a handler that writes the return value of handle
// as a JSON response. If handle returns an error, it is passed through
// the error mapper.
//
// Note that the Params argument passed to handle will not
// have its PathPattern set as that information is not available.
HandleJSON returns a handler that writes the return value of handle
as a JSON response. If handle returns an error, it is passed through
the error mapper.

Note that the Params argument passed to handle will not
have its PathPattern set as that information is not available.
// HandleJSON returns a handler that writes the return value of handle // as a JSON response . If handle returns an error it is passed through // the error mapper . // // Note that the Params argument passed to handle will not // have its PathPattern set as that information is not available .
func (srv *Server) HandleJSON(handle JSONHandler) httprouter.Handle {
	return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
		ctx := req.Context()
		val, err := handle(Params{
			Response: headerOnlyResponseWriter{w.Header()},
			Request:  req,
			PathVar:  p,
			Context:  ctx,
		})
		if err == nil {
			if err = WriteJSON(w, http.StatusOK, val); err == nil {
				return
			}
		}
		srv.WriteError(ctx, w, err)
	}
}
func ( srv * Server ) HandleJSON ( handle JSONHandler ) httprouter . Handle { return func ( w http . ResponseWriter , req * http . Request , p httprouter . Params ) { ctx := req . Context ( ) val , err := handle ( Params { Response : headerOnlyResponseWriter { w . Header ( ) } , Request : req , PathVar : p , Context : ctx , } ) if err == nil { if err = WriteJSON ( w , http . StatusOK , val ) ; err == nil { return } } srv . WriteError ( ctx , w , err ) } }
HandleJSON returns a handler that writes the return value of handle
as a JSON response.
HandleJSON returns a handler that writes the return value of handle as a JSON response .