Comments (7)
hi @hmgle I'd prefer to keep chi as just a router. If you need a responder, I suggest to use https://github.com/unrolled/render which works just fine with chi.
your code will look like:
import renderPkg "github.com/unrolled/render"
var render *render.Render
func init() {
render = renderPkg.New() // pass options if you want
}
func x() http.Handler {
r := chi.New()
r.Get("/", handler)
}
func handler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
// processing..
render.JSON(w, 200, responseObj)
}
another suggestion, is wrap the unrolled/render package by making your own "render" package that is a part of your project, and set defaults there so its setup to use across packages.
from chi.
So I'd like to understand if you prefer something like:
"render.RenderList(w, r, NewArticleListResponse(articles))
instead of something like unrolled/render does, based on interface{}...
Thanks for chi btw! :)
from chi.
The goals of chi are to stay minimal, allow full control without limitation of possibility or productivity. I guess the gap right now is that chi doesn't provide every library out of the box, you're expected to make your own choices for something like the responder. I will update the example to show how to wrap your own render responder.
from chi.
@hmgle here you go https://github.com/pressly/chi/blob/master/_examples/rest/main.go
and
https://github.com/pressly/chi/blob/master/_examples/rest/render/render.go
from chi.
Got it~ It looks elegant.
from chi.
Was the example linked in https://github.com/pressly/chi/blob/master/_examples/rest/render/render.go integrated into rest/main.go?
from chi.
@hugows yes exactly. Its now at: https://github.com/go-chi/chi/blob/master/_examples/rest/main.go
from chi.
Related Issues (20)
- How to test if a request path matches the pattern using chi router HOT 1
- chi.RouteContext(r.Context()).RoutePattern() returns ""
- Mount isn't compositing the route patterns HOT 1
- Unexpected Group behaviour HOT 1
- Can we log panics in one line? HOT 1
- log/slog's LogAttrs (and other methods) now requires a context as their first argument HOT 3
- Brotli compression not working
- Feature: Expose Context.methodsAllowed for use by MethodNotAllowedHandler
- Feature: on Go 1.22, fill `(*http.Request).PathValue` with URLParam data HOT 5
- Incorrect Route Matching Comment in chi.go
- [Doubt] Do you support i18n? HOT 4
- Possible bug can lead to security issue HOT 4
- URL params are not available inside middleware on the root router HOT 3
- Is jwtauth to validate jwt ? or can I create new jwt tokens using jwtauth? HOT 1
- Feature: on Go 1.22 pattern can start with an optional HTTP Method HOT 5
- bug: HandlerFunc does not support HTTP methods in patterns like #897
- Huma not respecting API Gateway path? HOT 1
- r.With(paginate) in documentation HOT 1
- When registering a custom Middleware and a custom NotFoundHandler, both are executed when a 404 URL is loaded HOT 1
- Custom middleware recovery having to be duplicated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chi.