forked from mtusi2026/mtusi2026lab2
33 lines
627 B
Go
33 lines
627 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
// Config — конфигурация, приходящая из окружения.
|
|
type Config struct {
|
|
Host string
|
|
Port int
|
|
Env string
|
|
}
|
|
|
|
// Load читает переменные окружения со значениями по умолчанию.
|
|
func Load() Config {
|
|
port := 8080
|
|
if v := os.Getenv("APP_PORT"); v != "" {
|
|
if p, err := strconv.Atoi(v); err == nil {
|
|
port = p
|
|
}
|
|
}
|
|
host := os.Getenv("APP_HOST")
|
|
if host == "" {
|
|
host = "0.0.0.0"
|
|
}
|
|
env := os.Getenv("APP_ENV")
|
|
if env == "" {
|
|
env = "lab"
|
|
}
|
|
return Config{Host: host, Port: port, Env: env}
|
|
}
|