Skip to content

feat: create proxy layer, refactor caching layer to use defined structured values#3

Merged
Pyr33x merged 12 commits into
masterfrom
feat/proxy
Nov 26, 2025
Merged

feat: create proxy layer, refactor caching layer to use defined structured values#3
Pyr33x merged 12 commits into
masterfrom
feat/proxy

Conversation

@Pyr33x

@Pyr33x Pyr33x commented Nov 26, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Full HTTP proxy with response caching (stores status, headers, and body) and X-Cache hit/miss headers
    • /clear endpoint to flush cached responses
    • Graceful shutdown for clean server termination
    • Environment-configurable origin URL and proxy port
  • Chores

    • Removed development watch script

✏️ Tip: You can customize this high-level summary in your review settings.

@Pyr33x Pyr33x self-assigned this Nov 26, 2025
@coderabbitai

coderabbitai Bot commented Nov 26, 2025

Copy link
Copy Markdown

Walkthrough

Refactors cache API to JSON-serialized typed responses, replaces sugared logger with structured zap.Logger, adds a Redis-backed HTTP proxy with cache-aware forwarding and a /clear endpoint, introduces server/proxy/origin config fields, implements a production main with graceful shutdown, and promotes several dependencies to direct requires.

Changes

Cohort / File(s) Summary
Cache Layer Refactor
internal/cache/cache.go
Renamed public interface and struct (CacheCaching, cacheCache), replaced *zap.SugaredLogger with *zap.Logger, added CacheValue (Status, Header, Body), changed Get to (*CacheValue, bool), Put to accept CacheValue, added Clear, and switched storage to JSON serialization/deserialization.
Proxy Server
internal/proxy/proxy.go, internal/proxy/server.go
Added Server, ProxyServer, OriginServer types and NewProxyServer(...) returning *http.Server; implemented Serve() handler, ServeProxy (key construction, HIT/MISS flow), forwarding to origin, caching responses, Clear endpoint, and WriteHeaders for responses with X-Cache.
Application Entry Point
main.go
Replaced placeholder main with app startup: load config/logger, create proxy server, start HTTP server, and run gracefulShutdown goroutine handling SIGINT/SIGTERM with a 10s shutdown timeout.
Configuration
pkg/config/config.go
Added Server struct and nested Origin (URL) and Proxy (Port) types; Config now includes Server; New() initializes Server fields from ORIGIN_URL and PROXY_PORT and adjusts logger initialization order.
Dependencies
go.mod
Promoted modules (godotenv, envy, redis/go-redis/v9, zap) from indirect to direct require entries.
Removed Build Script
watch.bash
Deleted simple watch script that invoked air.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Proxy as Proxy Handler (ServeProxy)
    participant Cache as Redis Cache
    participant Origin as Origin Server

    Client->>Proxy: HTTP Request (method + URL)
    Proxy->>Cache: Get(key)

    alt Cache HIT
        Cache-->>Proxy: (*CacheValue, true)
        Proxy->>Proxy: WriteHeaders(state: "HIT")
        Proxy-->>Client: Cached Response (status, headers, body)
    else Cache MISS
        Cache-->>Proxy: (nil, false)
        Proxy->>Origin: Forward Request
        Origin-->>Proxy: Response (Status, Headers, Body)
        Proxy->>Cache: Put(CacheValue)
        Proxy->>Proxy: WriteHeaders(state: "MISS")
        Proxy-->>Client: Response + X-Cache: MISS
    end

    Note over Proxy,Cache: /clear endpoint calls Cache.Clear()
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas to focus:
    • JSON serialization/deserialization of http.Header and large response bodies in internal/cache/cache.go.
    • Cache key construction and any URL normalization in internal/proxy/server.go.
    • Correct copying of headers/status and setting of X-Cache in WriteHeaders.
    • Error handling and timeouts when forwarding to origin and when interacting with Redis.
    • Graceful shutdown race conditions in main.go and server construction in internal/proxy/proxy.go.

Poem

🐇 I hopped from code to Redis bright,
Storing headers, status, byte by byte.
HITs hum softly, MISSes dart away,
A clear endpoint keeps caches gay,
Graceful sleeps end the server's night.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between c134e4c and 8a4538a.

📒 Files selected for processing (2)
  • internal/proxy/server.go (1 hunks)
  • main.go (1 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@Pyr33x Pyr33x merged commit 38cc426 into master Nov 26, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant