-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (34 loc) · 857 Bytes
/
main.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
package main
import (
"log"
"github.com/facebookgo/grace/gracehttp"
"github.com/gwleclerc/dummy-golang-test/cache"
"github.com/gwleclerc/dummy-golang-test/handlers"
"github.com/labstack/echo"
)
// ServerHeader middleware adds a `Server` header to the response.
func cacheMiddleware(store cache.Cache) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("cache", store)
return next(c)
}
}
}
func main() {
store, err := cache.New()
if err != nil {
log.Fatal(err)
}
defer store.Close()
cacheHandler := handlers.NewCacheHandler()
e := echo.New()
redis := e.Group("/redis")
{
redis.Use(cacheMiddleware(store))
redis.GET("/:key", cacheHandler.Get)
redis.POST("/:key", cacheHandler.Set)
}
e.Server.Addr = ":8080"
e.Logger.Fatal(gracehttp.Serve(e.Server))
}