mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 04:52:26 +00:00
- Removed obsolete files: `hanle_multi.go`, `logger.go`, `handle_com.go`, `handle_list.go`, `server.go`, and `utils.go` from the `general_server` and `sv1` packages. - Introduced new implementations for the `GeneralServer` and `HandlerV1` in the `core` package, enhancing the overall architecture. - Updated the `go.mod` and `go.sum` files to include new dependencies. - Added a new configuration structure in `config.yaml` and `config.go` for better management of application settings. - Implemented a Lua command handling mechanism in `handle_com.go` and `handle_list.go` for improved command execution. - Enhanced logging capabilities with a new logger setup in `logger.go`. - Added a new Lua script `http.lua` for handling HTTP requests.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
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"`
|
|
TLS `yaml:"tls"`
|
|
}
|
|
|
|
type TLS struct {
|
|
TlsEnabled string `yaml:"enabled" env-default:"false"`
|
|
CertFile string `yaml:"cert_file" env-default:"./cert/server.crt"`
|
|
KeyFile string `yaml:"key_file" env-default:"./cert/server.key"`
|
|
}
|
|
|
|
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"`
|
|
HTTPServer_Api `yaml:"api"`
|
|
}
|
|
|
|
type HTTPServer_Api struct {
|
|
LatestVer string `yaml:"latest-version" env-required:"true"`
|
|
Layers []string `yaml:"layers"`
|
|
}
|
|
|
|
type ConfigEnv struct {
|
|
ConfigPath string `env:"CONFIG_PATH" env-default:"./cfg/config.yaml"`
|
|
}
|
|
|
|
func MustLoadConfig() *ConfigConf {
|
|
log.SetOutput(os.Stderr)
|
|
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
|
|
}
|