Skip to content

Commit

Permalink
2024-09-05 01:19:17
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-streltsov committed Sep 5, 2024
1 parent e660797 commit c876725
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,11 @@ func init() {
}

func main() {
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
}
godotenv.Load() // Load .env file if it exists, ignore error if it doesn't

port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
port := getEnvWithDefault("PORT", "8080")

dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "database/database.sqlite3"
}
dbPath := getEnvWithDefault("DB_PATH", "database/database.sqlite3")

dbPath = os.Getenv("DB_PATH")
if dbPath == "" {
Expand All @@ -61,7 +53,7 @@ func main() {
defer db.Close()

if err := safebrowsing.InitSafeBrowsing(); err != nil {
log.Fatalf("Error initializing Safe Browsing: %v", err)
log.Printf("Error initializing Safe Browsing: %v", err)
}
defer safebrowsing.Close()

Expand Down Expand Up @@ -93,3 +85,11 @@ func main() {

log.Println("Server exiting")
}

func getEnvWithDefault(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}

0 comments on commit c876725

Please sign in to comment.