英文:
Is Gin support rewrite HTTP requests and forward them to the specific API groups?
问题
我的团队打算重构我们的gin http服务器,以支持按域名进行路由。例如,登录的旧URL是https://www.example.com/login
,而新的URL将是https://login.example.com/
。我打算重写HTTP请求并将它们转发到旧的/login
组,以便所有复杂而混乱的验证和中间件都可以应用到新的样式上。
在文档中似乎没有相关示例。
英文:
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.
答案1
得分: 1
我会帮你翻译以下内容:
我赞同使用反向代理(例如nginx、Caddy等)在你的服务前面进行路由。
我也可以理解,如果你想对路由有更多的控制,你可以使用中间件。gin引擎支持通过routerInstance.Use(middlewareFunc)
使用中间件函数。
中间件只是一个返回gin.HandlerFunc
的函数。我在网上找到了一组示例:https://sosedoff.com/2014/12/21/gin-middleware.html
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论