46 lines
731 B
Go
46 lines
731 B
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
var Config = struct {
|
|
BaseUrl string
|
|
Debug bool
|
|
CookieDomain string
|
|
AppPort int
|
|
}{
|
|
BaseUrl: "http://localhost:18765", // Default configurations
|
|
AppPort: 18765,
|
|
}
|
|
|
|
func init() {
|
|
var err error
|
|
|
|
// Load the environment
|
|
err = godotenv.Load()
|
|
if err != nil {
|
|
log.Fatal("Error loading .env file")
|
|
}
|
|
|
|
// Set debug config
|
|
Config.Debug = os.Getenv("DEBUG") == "True"
|
|
|
|
// Get the listening port
|
|
port, _ := strconv.Atoi(os.Getenv("APP_PORT"))
|
|
if err != nil && port > 0 {
|
|
Config.AppPort = port
|
|
}
|
|
|
|
// Set the base URL
|
|
baseURL := os.Getenv("APP_BASE_URL")
|
|
if baseURL != "" {
|
|
print("okay")
|
|
Config.BaseUrl = baseURL
|
|
}
|
|
}
|