This commit is contained in:
2025-11-26 11:31:09 +08:00
parent dd38813636
commit 7c87114b30
9 changed files with 65 additions and 46 deletions
+23 -3
View File
@@ -18,6 +18,7 @@ import (
"github.com/getsentry/sentry-go"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/cors"
@@ -152,8 +153,28 @@ func allowOnlyGrafana(next http.Handler, allowedIP string) http.Handler {
}
func main() {
// Initialize Sentry
// Load environment variables from .env file first
// Get current working directory for debugging
cwd, _ := os.Getwd()
log.Printf("Current working directory: %s", cwd)
err := godotenv.Load()
if err != nil {
log.Printf("ERROR: Failed to load .env file from default location: %v", err)
// Try with explicit path
err = godotenv.Load(".env")
if err != nil {
log.Fatalf("FATAL: Could not load .env file: %v. Tried paths: default and ./.env", err)
}
log.Println(".env file loaded successfully from ./.env")
} else {
log.Println(".env file loaded successfully")
}
// Verify GO_ENV is loaded
goEnv := os.Getenv("GO_ENV")
log.Printf("GO_ENV value after loading .env: '%s'", goEnv)
if goEnv == "" {
log.Fatal("GO_ENV is not set in main. Please set the GO_ENV environment variable.")
}
@@ -163,7 +184,7 @@ func main() {
log.Fatal("Sentry DSN is not set. Please set the DSN environment variable.")
}
err := sentry.Init(sentry.ClientOptions{
err = sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("DSN"),
TracesSampleRate: 1.0,
Environment: goEnv,
@@ -223,4 +244,3 @@ func main() {
}
log.Fatal(server.ListenAndServe())
}