33 lines
619 B
Go
33 lines
619 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.dev-null.rocks/alexohneander/distributed-cache/pkg/cache"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
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)
|
|
} else {
|
|
return c.String(http.StatusNotFound, "Key not found")
|
|
}
|
|
|
|
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, "")
|
|
}
|
|
}
|