Files
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 2a5ece0455 chore(deps): multiple updates (#76)
* chore(deps): bump golangci/golangci-lint-action from 3 to 9

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3 to 9.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3...v9)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-version: '9'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump github.com/prometheus/client_golang

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.20.5 to 1.23.2.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.20.5...v1.23.2)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-version: 1.23.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/prometheus/client_golang

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.22.0 to 1.23.2.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.22.0...v1.23.2)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-version: 1.23.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/go-playground/validator/v10

Bumps [github.com/go-playground/validator/v10](https://github.com/go-playground/validator) from 10.23.0 to 10.30.1.
- [Release notes](https://github.com/go-playground/validator/releases)
- [Commits](https://github.com/go-playground/validator/compare/v10.23.0...v10.30.1)

---
updated-dependencies:
- dependency-name: github.com/go-playground/validator/v10
  dependency-version: 10.30.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/gorilla/mux in /go-proxy-cache

Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/gorilla/mux/releases)
- [Commits](https://github.com/gorilla/mux/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/gorilla/mux
  dependency-version: 1.8.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump go.uber.org/zap in /go-proxy-cache

Bumps [go.uber.org/zap](https://github.com/uber-go/zap) from 1.24.0 to 1.27.1.
- [Release notes](https://github.com/uber-go/zap/releases)
- [Changelog](https://github.com/uber-go/zap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uber-go/zap/compare/v1.24.0...v1.27.1)

---
updated-dependencies:
- dependency-name: go.uber.org/zap
  dependency-version: 1.27.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump actions/checkout from 4 to 6

Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump actions/setup-go from 5 to 6

Bumps [actions/setup-go](https://github.com/actions/setup-go) from 5 to 6.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump golang.org/x/crypto in /go-auth-service

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.39.0 to 0.46.0.
- [Commits](https://github.com/golang/crypto/compare/v0.39.0...v0.46.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.46.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/prometheus/client_golang in /go-proxy-cache

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.23.0 to 1.23.2.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.23.0...v1.23.2)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-version: 1.23.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/stretchr/testify in /rpc-health-checker

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.10.0 to 1.11.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.10.0...v1.11.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-version: 1.11.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/golang-jwt/jwt/v5 in /go-auth-service

Bumps [github.com/golang-jwt/jwt/v5](https://github.com/golang-jwt/jwt) from 5.2.2 to 5.3.0.
- [Release notes](https://github.com/golang-jwt/jwt/releases)
- [Commits](https://github.com/golang-jwt/jwt/compare/v5.2.2...v5.3.0)

---
updated-dependencies:
- dependency-name: github.com/golang-jwt/jwt/v5
  dependency-version: 5.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

chore(deps): bump github.com/stretchr/testify in /go-proxy-cache

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.10.0 to 1.11.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.10.0...v1.11.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-version: 1.11.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-30 19:44:53 +04:00

132 lines
3.4 KiB
Go

package httpserver
import (
"context"
"encoding/json"
"io"
"net"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
"go.uber.org/zap"
"go-proxy-cache/internal/cache/service"
)
// Server represents the HTTP cache server
type Server struct {
cacheService *service.CacheService
logger *zap.Logger
server *http.Server
}
// NewServer creates a new cache HTTP server
func NewServer(cacheService *service.CacheService, logger *zap.Logger) *Server {
return &Server{
cacheService: cacheService,
logger: logger,
}
}
// StartUnixSocket starts the HTTP server on a Unix socket
func (s *Server) StartUnixSocket(socketPath string) error {
// Remove existing socket file
if err := os.RemoveAll(socketPath); err != nil {
s.logger.Warn("Failed to remove existing socket file", zap.String("path", socketPath), zap.Error(err))
}
// Create Unix socket listener
listener, err := net.Listen("unix", socketPath)
if err != nil {
return err
}
// Set socket permissions (readable/writable by all users for cross-container access)
if err := os.Chmod(socketPath, 0666); err != nil {
s.logger.Warn("Failed to set socket permissions", zap.String("path", socketPath), zap.Error(err))
}
router := s.createRouter()
s.server = &http.Server{
Handler: router,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
}
s.logger.Info("Starting cache HTTP server on Unix socket", zap.String("socket_path", socketPath))
return s.server.Serve(listener)
}
// Stop stops the HTTP server
func (s *Server) Stop(ctx context.Context) error {
s.logger.Info("Stopping cache HTTP server")
// Stop main server
if s.server != nil {
return s.server.Shutdown(ctx)
}
return nil
}
// createRouter creates and configures the HTTP router
func (s *Server) createRouter() *mux.Router {
router := mux.NewRouter()
// Cache endpoints
router.HandleFunc("/cache/get", s.handleGet).Methods("POST")
router.HandleFunc("/cache/set", s.handleSet).Methods("POST")
// Health check
router.HandleFunc("/health", s.handleHealth).Methods("GET")
// Cache info endpoint (equivalent to cache rules check)
router.HandleFunc("/cache/info", s.handleCacheInfo).Methods("POST")
return router
}
// handleHealth handles health check requests
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
s.writeResponse(w, map[string]interface{}{
"status": "healthy",
"time": time.Now().UTC(),
})
}
// parseRequest parses JSON request body
func (s *Server) parseRequest(r *http.Request, v interface{}) error {
body, err := io.ReadAll(r.Body)
if err != nil {
return err
}
defer func() { _ = r.Body.Close() }()
return json.Unmarshal(body, v)
}
// writeResponse writes JSON response
func (s *Server) writeResponse(w http.ResponseWriter, v interface{}) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(v); err != nil {
s.logger.Error("Failed to write response", zap.Error(err))
}
}
// writeErrorResponse writes error response
func (s *Server) writeErrorResponse(w http.ResponseWriter, message string, statusCode int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
response := map[string]interface{}{
"success": false,
"error": message,
}
if err := json.NewEncoder(w).Encode(response); err != nil {
s.logger.Error("Failed to write error response", zap.Error(err))
}
}