mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 19:52:25 +00:00
Refactor configuration structures and improve comments for clarity
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package config provides configuration management for the application.
|
||||
// config is built on top of the third-party module cleanenv
|
||||
package config
|
||||
|
||||
import (
|
||||
@@ -8,6 +10,7 @@ import (
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
// ConfigConf basic structure of configs
|
||||
type ConfigConf struct {
|
||||
Mode string `yaml:"mode" env-default:"dev"`
|
||||
ComDir string `yaml:"com_dir" env-default:"./com/"`
|
||||
@@ -17,26 +20,6 @@ type ConfigConf struct {
|
||||
Updates `yaml:"updates"`
|
||||
}
|
||||
|
||||
type Updates struct {
|
||||
UpdatesEnabled bool `yaml:"enabled" env-default:"false"`
|
||||
AllowAutoUpdates bool `yaml:"allow_auto_updates" env-default:"false"`
|
||||
AllowUpdates bool `yaml:"allow_updates" env-default:"false"`
|
||||
AllowDowngrades bool `yaml:"allow_downgrades" env-default:"false"`
|
||||
CheckInterval time.Duration `yaml:"check_interval" env-default:"2h"`
|
||||
RepositoryURL string `yaml:"repository_url" env-default:""`
|
||||
WantedVersion string `yaml:"wanted_version" env-default:"latest-stable"`
|
||||
}
|
||||
|
||||
type Internal struct {
|
||||
MetaDir string `yaml:"meta_dir" env-default:"./.meta/"`
|
||||
}
|
||||
|
||||
type TLS struct {
|
||||
TlsEnabled bool `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"`
|
||||
@@ -49,10 +32,33 @@ type HTTPServer_Api struct {
|
||||
Layers []string `yaml:"layers"`
|
||||
}
|
||||
|
||||
type TLS struct {
|
||||
TlsEnabled bool `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 Internal struct {
|
||||
MetaDir string `yaml:"meta_dir" env-default:"./.meta/"`
|
||||
}
|
||||
|
||||
type Updates struct {
|
||||
UpdatesEnabled bool `yaml:"enabled" env-default:"false"`
|
||||
AllowAutoUpdates bool `yaml:"allow_auto_updates" env-default:"false"`
|
||||
AllowUpdates bool `yaml:"allow_updates" env-default:"false"`
|
||||
AllowDowngrades bool `yaml:"allow_downgrades" env-default:"false"`
|
||||
CheckInterval time.Duration `yaml:"check_interval" env-default:"2h"`
|
||||
RepositoryURL string `yaml:"repository_url" env-default:""`
|
||||
WantedVersion string `yaml:"wanted_version" env-default:"latest-stable"`
|
||||
}
|
||||
|
||||
// ConfigEnv structure for environment variables
|
||||
type ConfigEnv struct {
|
||||
ConfigPath string `env:"CONFIG_PATH" env-default:"./cfg/config.yaml"`
|
||||
}
|
||||
|
||||
// MustLoadConfig loads the configuration from the specified path and environment variables.
|
||||
// Program will shutdown if any error occurs during loading.
|
||||
func MustLoadConfig() *ConfigConf {
|
||||
log.SetOutput(os.Stderr)
|
||||
var configEnv ConfigEnv
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package config
|
||||
|
||||
var UUIDLength int = 4
|
||||
// UUIDLength is uuids length for sessions. By default it is 16 bytes.
|
||||
var UUIDLength byte = 4
|
||||
|
||||
// ApiRoute setting for go-chi for main route for api requests
|
||||
var ApiRoute string = "/api/{ver}"
|
||||
// ComDirRoute setting for go-chi for main route for commands
|
||||
var ComDirRoute string = "/com"
|
||||
|
||||
// NodeVersion is the version of the node. It can be set by the build system or manually.
|
||||
// If not set, it will return "version0.0.0-none" by default
|
||||
var NodeVersion string
|
||||
var ActualFileNanme string = "actual.txt"
|
||||
// ActualFileName is a feature of the GoSally update system.
|
||||
// In the repository, the file specified in the variable contains the current information about updates
|
||||
var ActualFileName string = "actual.txt"
|
||||
|
||||
type _internalConsts struct{}
|
||||
type _serverConsts struct{}
|
||||
@@ -19,10 +26,10 @@ func (_ _updateConsts) GetNodeVersion() string {
|
||||
}
|
||||
return NodeVersion
|
||||
}
|
||||
func (_ _updateConsts) GetActualFileName() string { return ActualFileNanme }
|
||||
func (_ _updateConsts) GetActualFileName() string { return ActualFileName }
|
||||
|
||||
func GetInternalConsts() _internalConsts { return _internalConsts{} }
|
||||
func (_ _internalConsts) GetUUIDLength() int { return UUIDLength }
|
||||
func (_ _internalConsts) GetUUIDLength() byte { return UUIDLength }
|
||||
|
||||
func GetServerConsts() _serverConsts { return _serverConsts{} }
|
||||
func (_ _serverConsts) GetApiRoute() string { return ApiRoute }
|
||||
|
||||
Reference in New Issue
Block a user