Add configuration and v1 server implementation; create handler methods for command execution and listing

This commit is contained in:
alex
2025-06-22 17:09:47 +03:00
parent c15e6c5b15
commit 27bda702bd
14 changed files with 10 additions and 8 deletions

44
config/config.go Normal file
View File

@@ -0,0 +1,44 @@
package config
import (
"log"
"os"
"time"
"github.com/ilyakaznacheev/cleanenv"
)
type ConfigConf struct {
Mode string `yaml:"mode" env-default:"dev"`
ComDir string `yaml:"com_dir" env-default:"./com/"`
HTTPServer `yaml:"http_server"`
}
type HTTPServer struct {
Address string `yaml:"address" env-default:"0.0.0.0:8080"`
Timeout time.Duration `yaml:"timeout" env-default:"5s"`
IdleTimeout time.Duration `yaml:"idle_timeout" env-default:"60s"`
}
type ConfigEnv struct {
ConfigPath string `env:"CONFIG_PATH" env-default:"./cfg/config.yaml"`
}
func MustLoadConfig() *ConfigConf {
var configEnv ConfigEnv
if err := cleanenv.ReadEnv(&configEnv); err != nil {
log.Fatalf("Failed to read environment variables: %v", err)
os.Exit(1)
}
if _, err := os.Stat(configEnv.ConfigPath); os.IsNotExist(err) {
log.Fatalf("Config file does not exist: %s", configEnv.ConfigPath)
os.Exit(2)
}
var config ConfigConf
if err := cleanenv.ReadConfig(configEnv.ConfigPath, &config); err != nil {
log.Fatalf("Failed to read config file: %v", err)
os.Exit(3)
}
log.Printf("Configuration loaded successfully from %s", configEnv.ConfigPath)
return &config
}