Home > OS >  Is Gin support rewrite HTTP requests and forward them to the specific API groups?
Is Gin support rewrite HTTP requests and forward them to the specific API groups?

Time:11-10

My team is going to refactor our gin http server to support routing by domain. For example, the old url for login is https://www.example.com/login, and the new url will be https://login.example.com/. I was going to rewrite http requests and forward them to the old /login group so that all the validations and middlewares, which are very complicate and messy, could be apply to the new style.

Seems like there is no examples in the document.

CodePudding user response:

I'd second the suggestion to use a reverse proxy (e.g. nginx, Caddy, etc) in front of your services to do the routing.

I can also understand if you would like to have a little bit more control over the routing, you can use middlewares. The gin engine supports the use of middleware functions via routerInstance.Use(middlewareFunc).

A middleware is simply a function that returns gin.HandlerFunc. I found this set of examples on the Web: https://sosedoff.com/2014/12/21/gin-middleware.html

  • Related