[add] initial commit
This commit is contained in:
51
config/environment.go
Normal file
51
config/environment.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"gelvin/app/application"
|
||||
"os"
|
||||
)
|
||||
|
||||
const EnvPrefix = "GELVIN_"
|
||||
|
||||
type environment struct {
|
||||
Mode application.Mode
|
||||
UrlRoot string
|
||||
Version application.Version
|
||||
}
|
||||
|
||||
func Environment() environment {
|
||||
|
||||
var mode application.Mode
|
||||
switch getEnv("MODE") {
|
||||
case "TEST":
|
||||
mode = application.Test
|
||||
case "PRODUCTION":
|
||||
mode = application.Production
|
||||
default:
|
||||
mode = application.Debug
|
||||
}
|
||||
|
||||
var urlRoot string
|
||||
if urlRoot = getEnv("URL_ROOT"); urlRoot == "" {
|
||||
urlRoot = "/"
|
||||
}
|
||||
|
||||
version := parseVersion(getEnv("API_VERSION"))
|
||||
return environment{
|
||||
Mode: mode,
|
||||
UrlRoot: urlRoot,
|
||||
Version: version,
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key string) string {
|
||||
return os.Getenv(EnvPrefix + key)
|
||||
}
|
||||
|
||||
func parseVersion(s string) application.Version {
|
||||
version := application.Version{Major: 1}
|
||||
if s != "" {
|
||||
// TODO
|
||||
}
|
||||
return version
|
||||
}
|
||||
Reference in New Issue
Block a user