- Rename project from 'bookmann' to 'shelf' - Move all backend/ contents to root level (flatten structure) - Update Go module name from 'bookmann' to 'shelf' - Update all import paths to use new 'shelf' module - Update Dockerfile to work without backend/ subdirectory - Update docker-compose.yml to use new structure and rename containers - Update .gitignore for new file paths - Update README.md with new project name and structure - Regenerate database code with new module imports
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
ServerPort string
|
|
JWTSecret string
|
|
UploadPath string
|
|
DatabaseHost string
|
|
DatabasePort string
|
|
DatabaseUser string
|
|
DatabasePassword string
|
|
DatabaseName string
|
|
}
|
|
|
|
func LoadConfig() *Config {
|
|
return &Config{
|
|
ServerPort: getEnv("SERVER_PORT", "8080"),
|
|
DatabaseHost: getEnv("DATABASE_HOST", "localhost"),
|
|
DatabasePort: getEnv("DATABASE_PORT", "5432"),
|
|
DatabaseUser: getEnv("DATABASE_USER", "postgres"),
|
|
DatabasePassword: getEnv("DATABASE_PASSWORD", "password"),
|
|
DatabaseName: getEnv("DATABASE_NAME", "ebookdb"),
|
|
JWTSecret: getEnv("JWT_SECRET", "your-secret-key"),
|
|
UploadPath: getEnv("UPLOAD_PATH", "./uploads"),
|
|
}
|
|
}
|
|
|
|
func (c *Config) DatabaseURL() string {
|
|
return fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable",
|
|
c.DatabaseUser, c.DatabasePassword, c.DatabaseHost, c.DatabasePort, c.DatabaseName)
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|