Coder Social home page Coder Social logo

gin-adapter's People

Contributors

gwatts avatar housek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gin-adapter's Issues

Expose swappedResponseWriter

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
}

Custom middleware to get status code does not seem to work

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

Doesn't work for NYT GZip Middleware

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 ) )
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.