Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created April 28, 2020 21:19
Show Gist options
  • Save kimihito/9c5ec449e119dd8fb98bf1e076d602b8 to your computer and use it in GitHub Desktop.
Save kimihito/9c5ec449e119dd8fb98bf1e076d602b8 to your computer and use it in GitHub Desktop.
Running labstack/echo on Zeit now (Vercel) Serverless function
// set api/index.go
package handler
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello World")
}
func hello2(c echo.Context) error {
return c.String(http.StatusOK, "Hello World2")
}
func Handler(w http.ResponseWriter, r *http.Request) {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.GET("/api/", hello)
e.GET("/api/2", hello2)
e.ServeHTTP(w, r)
}
{
"name": "hoge",
"version": 2,
"routes": [
{ "src": "/api/.*", "dest": "api/index.go" }
]
}
@LuccChagas
Copy link

Could you show your main file?

@theCompanyDream
Copy link

Not sure if you still need help with this but essentially handler files don't need main.go handler is the main function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment