You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to deploy go-zero rest services using serverless architecture, such as vervcel serverless. If the server has ServeHTTP method, I can directly connect to the vercel function and deploy the service on vercel.
I think this method is not only used for testing, it has a greater purpose. Frameworks like gin, echo, etc. all support ServeHTTP and can be connected to the vercel platform.
Unfortunately it doesn't work properly. I think I still need to add a NewRestServer with option. Only bindRoutes when starting. Or is there any better way?
// Serve is for serverless purpose.// Don't use it when using the Server in regular HTTP server mode.// see https://vercel.com/docs/functions/runtimes/gofunc (s*Server) Serve(w http.ResponseWriter, r*http.Request) {
s.router.ServeHTTP(w, r)
}
// BindRoutes binds the routes to the server.// It's for serverless purpose.// You should call it before calling Serve().func (s*Server) BindRoutes() error {
returns.ngin.bindRoutes(s.router)
}
changed the title [-]Why v1.8.1 remove ServeHTTP method? This method works on cloud computing platforms[/-][+]Why v1.8.1 remove ServeHTTP method? This method works on serverless services[/+]on May 26, 2025
Activity
kevwan commentedon May 24, 2025
It's only for test purpose.
The best practices is to create a rest.Server and addRoutes, then start the server.
jaronnie commentedon May 24, 2025
I want to deploy go-zero rest services using serverless architecture, such as vervcel serverless. If the server has ServeHTTP method, I can directly connect to the vercel function and deploy the service on vercel.
You can look https://vercel.com/docs/functions/runtimes/go
jaronnie commentedon May 24, 2025
Prior to version 1.8.1, go-zero services could be deployed on vercel, which is the best practice in serverless architecture.
jaronnie commentedon May 24, 2025
I think this method is not only used for testing, it has a greater purpose. Frameworks like gin, echo, etc. all support ServeHTTP and can be connected to the vercel platform.
jaronnie commentedon May 24, 2025
see this blog: https://www.minoic.top/%E5%9C%A8-vercel-%E4%B8%AD%E5%BB%BA%E7%AB%8B-go-gin-%E7%9A%84%E7%BD%91%E7%AB%99%E6%9C%8D%E5%8A%A1/
kevwan commentedon May 24, 2025
Got it. I'll investigate this and if necessary, I'll add it back.
But for the previous implementation, bindRoutes will be called for each request. It causes memory leak, and it's only used in test purpose.
Thanks for your feedback!
jaronnie commentedon May 25, 2025
Ok, looking forward to ServeHTTP being added back
kevwan commentedon May 25, 2025
hi @jaronnie
Would you please do a code review and check if the PR #4896 meets the requirement? Thanks!
jaronnie commentedon May 25, 2025
OK
jaronnie commentedon May 25, 2025
can you create a branch in zeromicro/go-zero. Then I can go get to test in workflows
kevwan commentedon May 25, 2025
Would you please use it from https://github.com/kevwan/go-zero/tree/rest/feat-servehttp
jaronnie commentedon May 25, 2025
I will use replace to solve.
replace ( github.com/zeromicro/go-zero => github.com/kevwan/go-zero v0.0.0-20250525082407-0d5bcc60fb34 )13 remaining items
kevwan commentedon May 26, 2025
You need to start the server, otherwise, options doesn't apply.
Also, bindRoutes for each request causes memory leak.
jaronnie commentedon May 26, 2025
Will using the Start() method result in listening to the port? Can NewRestServer add an option to not listen to the port?
jaronnie commentedon May 26, 2025
I'll start it and see if it works.
jaronnie commentedon May 26, 2025
Unfortunately it doesn't work properly. I think I still need to add a NewRestServer with option. Only bindRoutes when starting. Or is there any better way?
jaronnie commentedon May 26, 2025
add two methods:
usage:
it works ok with jzero-admin service ! Do you think this is okay? If it's ok, I can add this method to your branch
[-]Why v1.8.1 remove ServeHTTP method? This method works on cloud computing platforms[/-][+]Why v1.8.1 remove ServeHTTP method? This method works on serverless services[/+]kevwan commentedon May 26, 2025
Thanks for your feedback!
But I think it's better not to expose BindRoutes. Let me think it over and get back to you.
jaronnie commentedon May 26, 2025
OK. Looking forward to your solution.
fix(goctl): use rest.Serverless for generated integration tests (zero…