matryer / respond Goto Github PK
View Code? Open in Web Editor NEWIdiomatic API responses for Go.
License: MIT License
Idiomatic API responses for Go.
License: MIT License
Using HTTP status code 204 "No Content" to indicate that a request was successfully processed but no data is being returned leads to a panic.
-> gopkg.in/matryer/respond%2ev1.with
-> /home/david/go/pkg/mod/gopkg.in/matryer/[email protected]/respond.go:33
gopkg.in/matryer/respond%2ev1.WithStatus
/home/david/go/pkg/mod/gopkg.in/matryer/[email protected]/respond.go:76
main.UserListOne
/home/david/dev/wfi_api/user.go:123
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5.(*Mux).routeHTTP
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.Timeout.func1.1
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/timeout.go:45
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.Recoverer.func1
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/recoverer.go:38
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.RequestID.func1
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/request_id.go:76
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.RealIP.func1
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/realip.go:35
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.RequestLogger.func1.1
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/logger.go:57
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5.(*Mux).ServeHTTP
/home/david/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:88
net/http.serverHandler.ServeHTTP
/usr/local/go/src/net/http/server.go:2879
net/http.(*conn).serve
/usr/local/go/src/net/http/server.go:1930
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3034```
Due to the changes in Go1.7+ and the implementation of a native Context, the respond.Before operation fails due to the original request being duplicated within WithContext and not available to the Before handler.
Example:
func (r *Request) WithContext(ctx context.Context) *Request {
if ctx == nil {
panic("nil context")
}
r2 := new(Request)
*r2 = *r
r2.ctx = ctx
return r2
}
This sample code will not be able to access the original data object to resolve the .Public interface:
responder.Before = func(w http.ResponseWriter, r *http.Request, status int, data interface{}) (int, interface{}) {
if err, ok := data.(error); ok {
return status, map[string]interface{}{"error": err.Error()}
}
if obj, ok := data.(interface {
Public() interface{}
}); ok {
return status, obj.Public()
}
return status, data
}
If the encoding fails, respond panics (https://github.com/matryer/respond/blob/master/respond.go#L33). However, it has already written out headers (https://github.com/matryer/respond/blob/master/respond.go#L28), so it's not possible to recover and display an error page, using e.g. this: https://github.com/dimfeld/httptreemux#panic-handling
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.