Adds godotenv and fixes filtering logic
This commit is contained in:
parent
20c25e2f2d
commit
812a8f321c
4 changed files with 28 additions and 6 deletions
|
|
@ -9,5 +9,6 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/felixge/httpsnoop v1.0.3 // indirect
|
github.com/felixge/httpsnoop v1.0.3 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.28 // indirect
|
github.com/mattn/go-sqlite3 v1.14.28 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,7 @@ github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyE
|
||||||
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
|
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
|
||||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
||||||
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,11 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
@ -31,6 +34,17 @@ type StorageConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() (*Config, error) {
|
func Load() (*Config, error) {
|
||||||
|
// Load .env file if it exists
|
||||||
|
// Look for .env file in the project root (one level up from proxy/)
|
||||||
|
envPath := filepath.Join("..", ".env")
|
||||||
|
if err := godotenv.Load(envPath); err != nil {
|
||||||
|
// If .env doesn't exist in parent directory, try current directory
|
||||||
|
if err := godotenv.Load(".env"); err != nil {
|
||||||
|
// .env file is optional, so we just log and continue
|
||||||
|
// This allows the app to work with system environment variables only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
Server: ServerConfig{
|
Server: ServerConfig{
|
||||||
Port: getEnv("PORT", "3001"),
|
Port: getEnv("PORT", "3001"),
|
||||||
|
|
|
||||||
|
|
@ -73,15 +73,20 @@ func (s *sqliteStorageService) SaveRequest(request *model.RequestLog) (string, e
|
||||||
return "", fmt.Errorf("failed to marshal body: %w", err)
|
return "", fmt.Errorf("failed to marshal body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract model from body if available
|
// Model should already be set by the handler
|
||||||
var modelName string
|
modelName := request.Model
|
||||||
if body, ok := request.Body.(map[string]interface{}); ok {
|
if modelName == "" {
|
||||||
if model, ok := body["model"].(string); ok {
|
// Defensive fallback: try to extract from body if somehow not set
|
||||||
modelName = model
|
if body, ok := request.Body.(map[string]interface{}); ok {
|
||||||
request.Model = model // Also set it in the struct
|
if model, ok := body["model"].(string); ok {
|
||||||
|
modelName = model
|
||||||
|
request.Model = model
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("🔧 Saving request with model: '%s' (ID: %s)", modelName, request.RequestID)
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO requests (id, timestamp, method, endpoint, headers, body, user_agent, content_type, model)
|
INSERT INTO requests (id, timestamp, method, endpoint, headers, body, user_agent, content_type, model)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue