begin
This commit is contained in:
52
server/config/config.go
Normal file
52
server/config/config.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user