mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-07-06 04:04:57 +00:00
refactor: reorganize struct fields, add new handlers and storage backends
- [x] Reorder struct fields across codebase for consistency - [x] Add analytics event handlers and tests - [x] Add authentication API key management handlers and tests - [x] Add pre-warming control handlers and tests - [x] Implement S3 storage backend with tests - [x] Implement SMB/CIFS storage backend with tests - [x] Add CDN middleware tests - [x] Integrate analytics tracking into cache manager - [x] Add S3 and SMB storage initialization in app setup - [x] Add CDN caching to proxy handlers - [x] Remove distributed locking (Redis lock manager) - [x] Remove proxy common package and utilities - [x] Remove standalone HTTP server package - [x] Remove logger middleware - [x] Simplify error handling utilities - [x] Update config with S3 and SMB options - [x] Update cache manager signature to include analytics
This commit is contained in:
@@ -35,23 +35,3 @@ func Init(cfg Config) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get returns the global logger
|
||||
func Get() *zerolog.Logger {
|
||||
return &log.Logger
|
||||
}
|
||||
|
||||
// WithFields returns a logger with additional fields
|
||||
func WithFields(fields map[string]interface{}) *zerolog.Logger {
|
||||
logger := log.Logger
|
||||
for k, v := range fields {
|
||||
logger = logger.With().Interface(k, v).Logger()
|
||||
}
|
||||
return &logger
|
||||
}
|
||||
|
||||
// WithRequestID returns a logger with request ID
|
||||
func WithRequestID(requestID string) *zerolog.Logger {
|
||||
logger := log.With().Str("request_id", requestID).Logger()
|
||||
return &logger
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// responseWriter wraps http.ResponseWriter to capture status code
|
||||
type responseWriter struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
written int64
|
||||
}
|
||||
|
||||
func (rw *responseWriter) WriteHeader(code int) {
|
||||
rw.statusCode = code
|
||||
rw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (rw *responseWriter) Write(b []byte) (int, error) {
|
||||
n, err := rw.ResponseWriter.Write(b)
|
||||
rw.written += int64(n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Middleware is HTTP middleware for request logging
|
||||
func Middleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
|
||||
// Generate request ID
|
||||
requestID := r.Header.Get("X-Request-ID")
|
||||
if requestID == "" {
|
||||
requestID = "req_" + uuid.New().String()[:8]
|
||||
}
|
||||
|
||||
// Wrap response writer
|
||||
rw := &responseWriter{
|
||||
ResponseWriter: w,
|
||||
statusCode: http.StatusOK,
|
||||
}
|
||||
|
||||
// Set request ID in response header
|
||||
rw.Header().Set("X-Request-ID", requestID)
|
||||
|
||||
// Call next handler
|
||||
next.ServeHTTP(rw, r)
|
||||
|
||||
// Log request
|
||||
duration := time.Since(start)
|
||||
log.Info().
|
||||
Str("request_id", requestID).
|
||||
Str("method", r.Method).
|
||||
Str("path", r.URL.Path).
|
||||
Str("remote_addr", r.RemoteAddr).
|
||||
Str("user_agent", r.UserAgent()).
|
||||
Int("status", rw.statusCode).
|
||||
Int64("bytes", rw.written).
|
||||
Dur("duration_ms", duration).
|
||||
Msg("HTTP request")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user