35 lines
589 B
Go
35 lines
589 B
Go
|
|
package config
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"strconv"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Config struct {
|
||
|
|
ServerPort string
|
||
|
|
BaseURL string
|
||
|
|
}
|
||
|
|
|
||
|
|
func Load() *Config {
|
||
|
|
return &Config{
|
||
|
|
ServerPort: getEnv("SERVER_PORT", "3100"),
|
||
|
|
BaseURL: getEnv("BASE_URL", "http://localhost:3100"),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func getEnv(key, defaultValue string) string {
|
||
|
|
if value := os.Getenv(key); value != "" {
|
||
|
|
return value
|
||
|
|
}
|
||
|
|
return defaultValue
|
||
|
|
}
|
||
|
|
|
||
|
|
func getEnvAsInt(key string, defaultValue int) int {
|
||
|
|
if value := os.Getenv(key); value != "" {
|
||
|
|
if intValue, err := strconv.Atoi(value); err == nil {
|
||
|
|
return intValue
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return defaultValue
|
||
|
|
}
|