forked from mtusi2026/mtusi2026lab2
feat:lab1-catchup
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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}
|
||||
}
|
||||
Reference in New Issue
Block a user