71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
const (
|
|
DEFAULT_DB_TYPE = "turso"
|
|
DEFAULT_DB_URL = "lassistanoque.db"
|
|
DEFAULT_HTTP_PORT = 3000
|
|
DEFAULT_STORAGE_TYPE = "database"
|
|
)
|
|
|
|
type Config struct {
|
|
DatabaseType string
|
|
DatabaseURL string
|
|
HttpPort int
|
|
JWTSecret string
|
|
StorageType string // Database, S3, filesystem
|
|
StoragePath string // filesystem
|
|
StorageS3Bucket string // S3
|
|
StorageS3Endpoint string // S3
|
|
StorageS3AccessKeyID string // S3
|
|
StorageS3AccessKeySecret string // S3
|
|
StorageS3UseSSL string // S3
|
|
}
|
|
|
|
var config *Config
|
|
|
|
func GetConfig() *Config {
|
|
|
|
if config == nil {
|
|
godotenv.Load()
|
|
|
|
databaseType := os.Getenv("LASSISTANOQUE_DB_TYPE")
|
|
if databaseType == "" {
|
|
databaseType = DEFAULT_DB_TYPE
|
|
}
|
|
databaseURL := os.Getenv("LASSISTANOQUE_DB_URL")
|
|
if databaseURL == "" {
|
|
databaseURL = DEFAULT_DB_URL
|
|
}
|
|
httpPort, _ := strconv.Atoi(os.Getenv("LASSISTANOQUE_HTTP_PORT"))
|
|
if httpPort == 0 {
|
|
httpPort = DEFAULT_HTTP_PORT
|
|
}
|
|
jwtsecret := os.Getenv("LASSISTANOQUE_JWT_SECRET")
|
|
if jwtsecret == "" {
|
|
log.Fatal("LASSISTANOQUE_JWT_SECRET must be set")
|
|
}
|
|
storageType := os.Getenv("LASSISTANOQUE_STORAGE_TYPE")
|
|
if storageType == "" {
|
|
storageType = DEFAULT_STORAGE_TYPE
|
|
}
|
|
|
|
config = &Config{
|
|
DatabaseType: databaseType,
|
|
DatabaseURL: databaseURL,
|
|
HttpPort: httpPort,
|
|
JWTSecret: jwtsecret,
|
|
StorageType: storageType,
|
|
}
|
|
|
|
}
|
|
return config
|
|
}
|