feat(server): add cache to context

master
Xeronith 2022-09-29 16:58:21 +03:30
rodzic e0ccadf480
commit 63b297d93d
3 zmienionych plików z 12 dodań i 5 usunięć

Wyświetl plik

@ -11,6 +11,7 @@ type (
GUID() string
Config() IConfig
Storage() IStorage
Cache() ICache
Request() IRequest
Response() IResponse
StringUtil() IStringUtil

Wyświetl plik

@ -25,15 +25,17 @@ import (
type httpServerContext struct {
underlyingContext *fiber.Ctx
cache ICache
request IRequest
response IResponse
stringUtil IStringUtil
httpClient *http.Client
}
func newContext(underlyingContext *fiber.Ctx) IContext {
func newContext(underlyingContext *fiber.Ctx, cache ICache) IContext {
return &httpServerContext{
underlyingContext: underlyingContext,
cache: cache,
request: newRequest(underlyingContext),
response: newResponse(underlyingContext),
stringUtil: utility.NewStringUtil(),
@ -91,6 +93,10 @@ func (context *httpServerContext) Storage() IStorage {
return nil
}
func (context *httpServerContext) Cache() ICache {
return context.cache
}
func (context *httpServerContext) Request() IRequest {
return context.request
}

Wyświetl plik

@ -104,19 +104,19 @@ func (server *httpServer) Bind(routes ...IRoute) {
switch route.Method() {
case HttpGet:
server.framework.Get(route.Path(), func(underlyingContext *fiber.Ctx) error {
return route.Handler()(newContext(underlyingContext))
return route.Handler()(newContext(underlyingContext, server.cache))
})
case HttpPost:
server.framework.Post(route.Path(), func(underlyingContext *fiber.Ctx) error {
return route.Handler()(newContext(underlyingContext))
return route.Handler()(newContext(underlyingContext, server.cache))
})
case HttpPut:
server.framework.Put(route.Path(), func(underlyingContext *fiber.Ctx) error {
return route.Handler()(newContext(underlyingContext))
return route.Handler()(newContext(underlyingContext, server.cache))
})
case HttpDelete:
server.framework.Delete(route.Path(), func(underlyingContext *fiber.Ctx) error {
return route.Handler()(newContext(underlyingContext))
return route.Handler()(newContext(underlyingContext, server.cache))
})
default:
panic("unsupported_method")