gwatts / gin-adapter Goto Github PK
View Code? Open in Web Editor NEWAdapt standard Go HTTP middleware packages for use with Gin
License: MIT License
Adapt standard Go HTTP middleware packages for use with Gin
License: MIT License
Respectfully request that you expose swappedResponseWriter
for better compatibility with authBoss. This might not be the only package with this type of issue.
In their design, they expect a http.Writer
of a particular type (ClientStateResponseWriter
) when writing responses. It's relatively easy to work around if swappedResponseWriter
is exposed as SwappedResponseWriter
(currently I have a local copy of adapter.go to make things work...):
import (
// ...
_ "github.com/volatiletech/authboss/v3"
)
func (w swappedResponseWriter) UnderlyingResponseWriter() http.ResponseWriter {
return w.w
}
we have a simple custom middleware to log the status code of the response like follow:
import (
"github.com/urfave/negroni"
adapter "github.com/gwatts/gin-adapter"
)
func statusCodeMiddleware() func(h http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
lrw := negroni.NewResponseWriter(rw) // this provides a Wrapper ResponseWrite that overrides the "WriteHeader(code int)" to populate it's own "statusCode" field
h.ServeHTTP(lrw, r)
statusCode := lrw.Status()
log.Printf("############# %d -%s ###########", statusCode, http.StatusText(statusCode))
})
}
}
router := gin.Default()
rotuer.Use(adapter.Wrap(statusCodeMiddleware()))
But the statusCode is being logged as 0 (default 0 value)
2021/04/24 16:45:03 ############# 0 - ###########
go version go1.15.6 darwin/amd64
gin-adapter doesn't compress the output, although WrapHH does...
import (
"github.com/gin-gonic/gin"
"github.com/NYTimes/gziphandler"
"github.com/gwatts/gin-adapter"
)
oRouteHandler := gin.Default()
oRouteHandler.Use( adapter.Wrap( gziphandler.GzipHandler ) )
...
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.