Skip to content

Instantly share code, notes, and snippets.

@ykyuen
Created April 8, 2019 17:55
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 ykyuen/7ba0141696939900a684bd92570f33d1 to your computer and use it in GitHub Desktop.
Save ykyuen/7ba0141696939900a684bd92570f33d1 to your computer and use it in GitHub Desktop.
handling-http-request-in-go-echo-framework-1-02
package api
import (
"fmt"
"net/http"
"github.com/labstack/echo"
"gitlab.com/ykyuen/golang-echo-template-example/model"
)
func GetFullName(c echo.Context) error {
// Bind the input data to ExampleRequest
exampleRequest := new(model.ExampleRequest)
if err := c.Bind(exampleRequest); err != nil {
return err
}
// Manipulate the input data
greeting := exampleRequest.FirstName + " " + exampleRequest.LastName
return c.JSONBlob(
http.StatusOK,
[]byte(
fmt.Sprintf(`{
"first_name": %q,
"last_name": %q,
"msg": "Hello %s"
}`, exampleRequest.FirstName, exampleRequest.LastName, greeting),
),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment