feat: initialize cache and use it in context
This commit is contained in:
23
api/cache.go
23
api/cache.go
@@ -1,11 +1,30 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.dev-null.rocks/alexohneander/distributed-cache/pkg/cache"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func GetItem(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "")
|
||||
func GetItem(cache *cache.Cache) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
cachedObj, found := cache.Get("key")
|
||||
|
||||
resp := ""
|
||||
|
||||
if found {
|
||||
resp = fmt.Sprintf("%+v", cachedObj)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func PostItem(cache *cache.Cache) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
cache.Set("key", "value")
|
||||
return c.String(http.StatusCreated, "")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user