mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
* feat: add security middleware, graphql apq, and improved linting - Add RateLimit, RequestValidation, and CORS middleware. - Configure middleware chain in API server. - Implement Redis cache for GraphQL Automatic Persisted Queries. - Add .golangci.yml and fix linting issues (shadowing, timeouts). * feat: security, caching and linting config - Fix .golangci.yml config for govet shadow check - (Previous changes: Security middleware, GraphQL APQ, Linting fixes) * fix: resolve remaining lint errors - Fix unhandled errors in tests (errcheck) - Define constants for repeated strings (goconst) - Suppress high complexity warnings with nolint:gocyclo - Fix integer overflow warnings (gosec) - Add package comments - Split long lines (lll) - Rename Analyse -> Analyze (misspell) - Fix naked returns and unused params --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
30 lines
753 B
Go
30 lines
753 B
Go
// Package cache provides cache implementations and adapters.
|
|
package cache
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// GraphQLCacheAdapter adapts the RedisCache to the graphql.Cache[string] interface
|
|
type GraphQLCacheAdapter struct {
|
|
RedisCache *RedisCache
|
|
}
|
|
|
|
// Get looks up a key in the cache
|
|
func (a *GraphQLCacheAdapter) Get(ctx context.Context, key string) (string, bool) {
|
|
// gqlgen APQ stores strings.
|
|
var s string
|
|
err := a.RedisCache.Get(ctx, key, &s)
|
|
if err != nil {
|
|
return "", false
|
|
}
|
|
return s, true
|
|
}
|
|
|
|
// Add adds a key to the cache
|
|
func (a *GraphQLCacheAdapter) Add(ctx context.Context, key, value string) {
|
|
// Use default TTL of 24 hours for APQ. The interface does not provide TTL.
|
|
_ = a.RedisCache.Set(ctx, key, value, 24*time.Hour)
|
|
}
|