Skip to content

Instantly share code, notes, and snippets.

@karolhrdina
Last active February 10, 2020 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karolhrdina/56e01bd1554fe1b83aba3bc09cae95bc to your computer and use it in GitHub Desktop.
Save karolhrdina/56e01bd1554fe1b83aba3bc09cae95bc to your computer and use it in GitHub Desktop.
Question about echo server
package main
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
)
func main() {
// Echo instance
e := echo.New()
// Routes
e.POST("/:product/foo/bar", recovery)
e.GET("/hello/world", hello)
// Start server
e.Logger.Fatal(e.Start(":1323"))
}
func recovery(c echo.Context) error {
product := c.Param("product")
return c.String(http.StatusOK, fmt.Sprintf("Product '%s' recovered", product))
}
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
#!/bin/bash
# This works
curl -XGET localhost:1323/hello/world
# This works
curl -XPOST localhost:1323/hatatitla/foo/bar
# Following two calls don't work (they hang the echo server)
curl -XPOST localhost:1323/hatatitla/foo/barsomethigelse
curl -XGET localhost:1323/hello/worldabrakadabra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment