-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.go
89 lines (68 loc) · 1.98 KB
/
echo.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
// import (
// "context"
// "math/rand"
// "net/http"
// "time"
// "github.com/labstack/echo/v4"
// "github.com/labstack/echo/v4/middleware"
// "github.com/labstack/gommon/log"
// )
// func echoApp() {
// e := echo.New()
// e.HideBanner = true
// s := &http.Server{
// Addr: ":1323",
// ReadTimeout: 20 * time.Minute,
// WriteTimeout: 20 * time.Minute,
// }
// e.Use(middleware.Logger())
// e.Use(middleware.Recover())
// e.Logger.SetLevel(log.DEBUG)
// dbPool := initDb()
// env := &Env{dbPool: dbPool}
// defer dbPool.Close()
// e.GET("/", func(c echo.Context) error {
// return c.String(http.StatusOK, "Hello, World!")
// })
// e.GET("/time", getSystemTime)
// e.GET("/db", env.getDbTime)
// e.GET("/closure", getDbTimeByClosure(env))
// e.Logger.Fatal(e.StartServer(s))
// }
// func (env *Env) getDbTime(c echo.Context) error {
// var now time.Time
// // following log command doesn't works.
// // have to look into that.
// log.Debug("Querying DB for time.")
// err := env.dbPool.QueryRow(context.Background(), "select now()").Scan(&now)
// if err != nil {
// panic(err)
// }
// var content response
// content.Response = "DB call check"
// content.Timestamp = now
// content.Random = rand.Intn(1000)
// return c.JSON(http.StatusOK, &content)
// }
// func getSystemTime(c echo.Context) error {
// var content response
// content.Response = "System time check"
// content.Timestamp = time.Now().UTC()
// content.Random = rand.Intn(1000)
// return c.JSON(http.StatusOK, &content)
// }
// func getDbTimeByClosure(env *Env) echo.HandlerFunc {
// return func(c echo.Context) error {
// var now time.Time
// err := env.dbPool.QueryRow(context.Background(), "select now()").Scan(&now)
// if err != nil {
// panic(err)
// }
// var content response
// content.Response = "DB call check by closure"
// content.Timestamp = now
// content.Random = rand.Intn(1000)
// return c.JSON(http.StatusOK, &content)
// }
// }