This commit is contained in:
metacryst
2025-09-06 20:26:07 -05:00
parent 7194b48b14
commit eff0c160a5
47 changed files with 2470 additions and 254 deletions

52
server/config/config.go Normal file
View File

@@ -0,0 +1,52 @@
package config
import (
"fmt"
"os"
"strconv"
"github.com/joho/godotenv"
)
var ENV string
// URLs
var BASE_URL string
const PORT = "3004"
// Auth
var JWT_SECRET string
// Logging
var LOG_TO_FILE bool
func SetConfiguration() {
fmt.Println("setting configuration for server")
err := godotenv.Load()
if err != nil {
fmt.Println("no .env file found. Needs to be added to server directory.")
}
ENV = os.Getenv("ENV")
if ENV != "production" && ENV != "development" {
fmt.Println("invalid value for ENV, must be 'development' or 'production'")
os.Exit(1)
}
BASE_URL = os.Getenv("BASE_URL")
if BASE_URL == "" {
fmt.Println("BASE_URL not provided, aborting")
os.Exit(1)
}
JWT_SECRET = os.Getenv("JWT_SECRET")
if JWT_SECRET == "" {
fmt.Println("JWT_SECRET not provided, aborting")
os.Exit(1)
}
LOG_TO_FILE, err = strconv.ParseBool(os.Getenv("LOG_TO_FILE"))
if err != nil {
LOG_TO_FILE = false
}
}