mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(server): initialize project skeleton with db and api setup
Establish the foundational structure for the ez-api server. Key changes include: - Set up main entry point with graceful shutdown and Gin router - Configure database connections for PostgreSQL (GORM) and Redis - Define core data models (User, Provider, Key, Model) - Implement configuration loading and basic key creation handler - Add Dockerfile for multi-stage builds and .gitignore
This commit is contained in:
58
internal/config/config.go
Normal file
58
internal/config/config.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig
|
||||
Postgres PostgresConfig
|
||||
Redis RedisConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port string
|
||||
}
|
||||
|
||||
type PostgresConfig struct {
|
||||
DSN string
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
Addr string
|
||||
Password string
|
||||
DB int
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
return &Config{
|
||||
Server: ServerConfig{
|
||||
Port: getEnv("EZ_API_PORT", "8080"),
|
||||
},
|
||||
Postgres: PostgresConfig{
|
||||
DSN: getEnv("EZ_PG_DSN", "host=localhost user=postgres password=postgres dbname=ezapi port=5432 sslmode=disable"),
|
||||
},
|
||||
Redis: RedisConfig{
|
||||
Addr: getEnv("EZ_REDIS_ADDR", "localhost:6379"),
|
||||
Password: getEnv("EZ_REDIS_PASSWORD", ""),
|
||||
DB: getEnvInt("EZ_REDIS_DB", 0),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func getEnvInt(key string, fallback int) int {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
if i, err := strconv.Atoi(value); err == nil {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user