kopia lustrzana https://github.com/reiver/greatape
feat(server): ⚡ add cache to context
rodzic
e0ccadf480
commit
63b297d93d
|
@ -11,6 +11,7 @@ type (
|
|||
GUID() string
|
||||
Config() IConfig
|
||||
Storage() IStorage
|
||||
Cache() ICache
|
||||
Request() IRequest
|
||||
Response() IResponse
|
||||
StringUtil() IStringUtil
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Ładowanie…
Reference in New Issue