feat: initialize cache and use it in context

This commit is contained in:
Alex Wellnitz
2025-09-12 15:42:21 +02:00
parent cba8e97a30
commit 71db22ef46
4 changed files with 34 additions and 3 deletions

View File

@@ -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, "")
}
}