-
-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load from .env - view updates - enable CDN
- Loading branch information
1 parent
5f2037a
commit 3cc63a0
Showing
21 changed files
with
328 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
package core | ||
|
||
import ( | ||
"errors" | ||
"github.com/go-yaml/yaml" | ||
"github.com/hunterlong/statup/types" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
type Config types.Config | ||
|
||
var ( | ||
VERSION string | ||
) | ||
|
||
func LoadConfig() (*Config, error) { | ||
var config *Config | ||
func LoadConfig() (*types.Config, error) { | ||
if os.Getenv("DB_CONN") != "" { | ||
return LoadUsingEnv() | ||
} | ||
Configs = new(types.Config) | ||
file, err := ioutil.ReadFile("config.yml") | ||
if err != nil { | ||
return nil, err | ||
return nil, errors.New("config.yml file not found - starting in setup mode") | ||
} | ||
err = yaml.Unmarshal(file, &Configs) | ||
CoreApp.DbConnection = Configs.Connection | ||
return Configs, err | ||
} | ||
|
||
func LoadUsingEnv() (*types.Config, error) { | ||
Configs = new(types.Config) | ||
if os.Getenv("DB_CONN") == "" { | ||
return nil, errors.New("Missing DB_CONN environment variable") | ||
} | ||
if os.Getenv("DB_HOST") == "" { | ||
return nil, errors.New("Missing DB_HOST environment variable") | ||
} | ||
if os.Getenv("DB_USER") == "" { | ||
return nil, errors.New("Missing DB_USER environment variable") | ||
} | ||
if os.Getenv("DB_PASS") == "" { | ||
return nil, errors.New("Missing DB_PASS environment variable") | ||
} | ||
if os.Getenv("DB_DATABASE") == "" { | ||
return nil, errors.New("Missing DB_DATABASE environment variable") | ||
} | ||
Configs.Connection = os.Getenv("DB_CONN") | ||
Configs.Host = os.Getenv("DB_HOST") | ||
Configs.Port = os.Getenv("DB_PORT") | ||
Configs.User = os.Getenv("DB_USER") | ||
Configs.Password = os.Getenv("DB_PASS") | ||
Configs.Database = os.Getenv("DB_DATABASE") | ||
CoreApp.DbConnection = os.Getenv("DB_CONN") | ||
CoreApp.Name = os.Getenv("NAME") | ||
CoreApp.Domain = os.Getenv("DOMAIN") | ||
if os.Getenv("USE_CDN") == "true" { | ||
CoreApp.UseCdn = true | ||
} | ||
return Configs, nil | ||
} | ||
|
||
func ifOr(val, def string) string { | ||
if val == "" { | ||
return def | ||
} | ||
err = yaml.Unmarshal(file, &config) | ||
Configs = config | ||
CoreApp.DbConnection = config.Connection | ||
return config, err | ||
return val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.