summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-09-04 14:45:23 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-09-04 14:45:23 +0530
commit75929861ba736aaa92306ded037ca631e38e06fc (patch)
treed58bb5334f7d8f8b104cdd6a48d5e61dff740e4b
parent6c4524551336753d6c2c3cd124061020a5f814bc (diff)
Initial trial - Hello World greeting w params
-rw-r--r--main.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/main.go b/main.go
index 6b1e80f..ab3f1ca 100644
--- a/main.go
+++ b/main.go
@@ -2,21 +2,34 @@ package main
import (
"net/http"
+
"github.com/labstack/echo/v4"
)
type HelloWorld struct {
- Message string `json:"message"`
+ Message string `json:"message"`
}
func main() {
- e := echo.New()
- e.GET("/hello", Greetings)
- e.Logger.Fatal(e.Start(":3000"))
+ e := echo.New()
+ e.GET("/hello", Greetings)
+ e.GET("/hello/:name", GreetingsWithParams)
+ e.Logger.Fatal(e.Start(":3000"))
}
+//http://localhost:3000/hello
+//{"message":"Hello World"}
func Greetings(c echo.Context) error {
- return c.JSON(http.StatusOK, HelloWorld{
- Message: "Hello World",
- })
+ return c.JSON(http.StatusOK, HelloWorld{
+ Message: "Hello World",
+ })
+}
+
+//http://localhost:3000/hello/Saumit
+//{"message":"Hello World, my name is Saumit"}
+func GreetingsWithParams(c echo.Context) error {
+ params := c.Param("name")
+ return c.JSON(http.StatusOK, HelloWorld{
+ Message: "Hello World, my name is " + params,
+ })
}