Skip to content

Instantly share code, notes, and snippets.

@hatajoe
Created April 26, 2016 00:55
Show Gist options
  • Save hatajoe/ba359b2820baf26e05e8e510419793c0 to your computer and use it in GitHub Desktop.
Save hatajoe/ba359b2820baf26e05e8e510419793c0 to your computer and use it in GitHub Desktop.
Sample: Parse JSON request body by labstack/echo
#!/bin/sh
curl -XPOST -H "content-type:application/json" -d '{"hoge": 1, "fuga": [2,3,4,5]}' localhost:1323
package main
import (
"fmt"
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
)
var json map[string]interface{} = map[string]interface{}{}
func main() {
e := echo.New()
e.POST("/", func(c echo.Context) error {
if err := c.Bind(&json); err != nil {
return err
}
return c.String(http.StatusOK, fmt.Sprintf("%v", json))
})
e.Run(standard.New(":1323"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment