-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
54 lines (45 loc) · 985 Bytes
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"net/http"
"strings"
"github.com/labstack/echo/v4"
)
// Index ...
type Index struct {
Hello string `json:"hello" query:"hello"`
}
// User ...
type User struct {
Name string `json:"name" query:"name"`
Surname string `json:"surname" query:"surname"`
Email string `json:"email" query:"email"`
}
// indexHandler ...
func indexHandler(c echo.Context) error {
index := &Index{
Hello: "world",
}
return c.JSON(http.StatusOK, index)
}
// userHandler ...
func userHandler(c echo.Context) error {
user := &User{
Name: "John",
Surname: "Doe",
Email: "john@doe.com",
}
return c.JSON(http.StatusOK, user)
}
// findUserHandler ...
func findUserHandler(c echo.Context) error {
param := c.Param("name")
user := &User{
Name: "Jane",
Surname: "Doe",
Email: "jane@doe.com",
}
if strings.ToLower(param) == strings.ToLower(user.Name) {
return c.JSON(http.StatusOK, user)
}
return c.String(http.StatusNotFound, "Not Found")
}