fix: error in creating default configuration
This commit is contained in:
@@ -75,6 +75,13 @@ func (GatewayServer) Config(configFile string) (*GatewayServer, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
logger.Info("Generating new configuration file...")
|
logger.Info("Generating new configuration file...")
|
||||||
|
//check if config directory does exist
|
||||||
|
if !util.FolderExists(ConfigDir) {
|
||||||
|
err := os.MkdirAll(ConfigDir, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
initConfig(ConfigFile)
|
initConfig(ConfigFile)
|
||||||
logger.Info("Server configuration file is available at %s", ConfigFile)
|
logger.Info("Server configuration file is available at %s", ConfigFile)
|
||||||
util.SetEnv("GOMA_CONFIG_FILE", ConfigFile)
|
util.SetEnv("GOMA_CONFIG_FILE", ConfigFile)
|
||||||
@@ -88,7 +95,6 @@ func (GatewayServer) Config(configFile string) (*GatewayServer, error) {
|
|||||||
return nil, fmt.Errorf("in file %q: %w", ConfigFile, err)
|
return nil, fmt.Errorf("in file %q: %w", ConfigFile, err)
|
||||||
}
|
}
|
||||||
logger.Info("Generating new configuration file...done")
|
logger.Info("Generating new configuration file...done")
|
||||||
logger.Info("Starting server with default configuration")
|
|
||||||
return &GatewayServer{
|
return &GatewayServer{
|
||||||
ctx: nil,
|
ctx: nil,
|
||||||
gateway: c.GatewayConfig,
|
gateway: c.GatewayConfig,
|
||||||
@@ -257,14 +263,6 @@ func initConfig(configFile string) {
|
|||||||
}
|
}
|
||||||
logger.Info("Configuration file has been initialized successfully")
|
logger.Info("Configuration file has been initialized successfully")
|
||||||
}
|
}
|
||||||
func Get() *Gateway {
|
|
||||||
if cfg == nil {
|
|
||||||
c := &Gateway{}
|
|
||||||
c.Setup(GetConfigPaths())
|
|
||||||
cfg = c
|
|
||||||
}
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
func (Gateway) Setup(conf string) *Gateway {
|
func (Gateway) Setup(conf string) *Gateway {
|
||||||
if util.FileExists(conf) {
|
if util.FileExists(conf) {
|
||||||
buf, err := os.ReadFile(conf)
|
buf, err := os.ReadFile(conf)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
|
const ConfigDir = "/etc/goma/" // Default configuration file
|
||||||
const ConfigFile = "/etc/goma/goma.yml" // Default configuration file
|
const ConfigFile = "/etc/goma/goma.yml" // Default configuration file
|
||||||
const accessControlAllowOrigin = "Access-Control-Allow-Origin" // Cors
|
const accessControlAllowOrigin = "Access-Control-Allow-Origin" // Cors
|
||||||
const serverName = "Goma"
|
const serverName = "Goma"
|
||||||
|
|||||||
@@ -24,6 +24,16 @@ func FileExists(filename string) bool {
|
|||||||
}
|
}
|
||||||
return !info.IsDir()
|
return !info.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FolderExists checks if the folder does exist
|
||||||
|
func FolderExists(name string) bool {
|
||||||
|
info, err := os.Stat(name)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return info.IsDir()
|
||||||
|
|
||||||
|
}
|
||||||
func GetStringEnv(key, defaultValue string) string {
|
func GetStringEnv(key, defaultValue string) string {
|
||||||
val := os.Getenv(key)
|
val := os.Getenv(key)
|
||||||
if val == "" {
|
if val == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user