mirror of https://github.com/statping/statping
removed env issues
parent
25d6f3b66a
commit
160979676b
|
@ -17,8 +17,8 @@ var (
|
|||
// Maintenance will automatically delete old records from 'failures' and 'hits'
|
||||
// this function is currently set to delete records 7+ days old every 60 minutes
|
||||
func Maintenance() {
|
||||
dur := utils.GetenvAs("REMOVE_AFTER", "2160h").Duration()
|
||||
interval := utils.GetenvAs("CLEANUP_INTERVAL", "1h").Duration()
|
||||
dur := utils.Params.GetDuration("REMOVE_AFTER")
|
||||
interval := utils.Params.GetDuration("CLEANUP_INTERVAL")
|
||||
|
||||
log.Infof("Database Cleanup runs every %s and will remove records older than %s", interval.String(), dur.String())
|
||||
ticker := interval
|
||||
|
|
|
@ -40,7 +40,7 @@ func hex2int(hexStr string) uint64 {
|
|||
|
||||
func prometheusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
promValues = []string{}
|
||||
prefix = utils.Getenv("PREFIX", "").(string)
|
||||
prefix = utils.Params.GetString("PREFIX")
|
||||
if prefix != "" {
|
||||
prefix = prefix + "_"
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ func UsingAssets(folder string) bool {
|
|||
if _, err := os.Stat(folder + "/assets"); err == nil {
|
||||
return true
|
||||
} else {
|
||||
useAssets := utils.Getenv("USE_ASSETS", false).(bool)
|
||||
useAssets := utils.Params.GetBool("USE_ASSETS")
|
||||
|
||||
if useAssets {
|
||||
log.Infoln("Environment variable USE_ASSETS was found.")
|
||||
|
|
|
@ -39,8 +39,8 @@ func Connect(configs *DbConfig, retry bool) error {
|
|||
}
|
||||
}
|
||||
|
||||
apiKey := utils.Getenv("API_KEY", utils.RandomString(24)).(string)
|
||||
apiSecret := utils.Getenv("API_SECRET", utils.RandomString(24)).(string)
|
||||
apiKey := utils.Params.GetString("API_KEY")
|
||||
apiSecret := utils.Params.GetString("API_SECRET")
|
||||
configs.ApiKey = apiKey
|
||||
configs.ApiSecret = apiSecret
|
||||
|
||||
|
@ -85,8 +85,8 @@ func CreateAdminUser(configs *DbConfig) error {
|
|||
log.Infoln(fmt.Sprintf("Core database does not exist, creating now!"))
|
||||
|
||||
if configs.Username == "" && configs.Password == "" {
|
||||
configs.Username = utils.Getenv("ADMIN_USER", "admin").(string)
|
||||
configs.Password = utils.Getenv("ADMIN_PASSWORD", "admin").(string)
|
||||
configs.Username = utils.Params.GetString("ADMIN_USER")
|
||||
configs.Password = utils.Params.GetString("ADMIN_PASSWORD")
|
||||
}
|
||||
|
||||
admin := &users.User{
|
||||
|
|
|
@ -6,14 +6,19 @@ import (
|
|||
)
|
||||
|
||||
func Samples() error {
|
||||
apiKey := utils.Getenv("API_KEY", utils.RandomString(16))
|
||||
apiSecret := utils.Getenv("API_SECRET", utils.RandomString(16))
|
||||
apiKey := utils.Params.GetString("API_KEY")
|
||||
apiSecret := utils.Params.GetString("API_SECRET")
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
apiKey = utils.RandomString(32)
|
||||
apiSecret = utils.RandomString(32)
|
||||
}
|
||||
|
||||
core := &Core{
|
||||
Name: "Statping Sample Data",
|
||||
Description: "This data is only used to testing",
|
||||
ApiKey: apiKey.(string),
|
||||
ApiSecret: apiSecret.(string),
|
||||
ApiKey: apiKey,
|
||||
ApiSecret: apiSecret,
|
||||
Domain: "http://localhost:8080",
|
||||
CreatedAt: utils.Now(),
|
||||
UseCdn: null.NewNullBool(false),
|
||||
|
|
|
@ -19,7 +19,7 @@ func findServiceByHash(hash string) *Service {
|
|||
}
|
||||
|
||||
func ServicesFromEnvFile() error {
|
||||
servicesEnv := utils.Getenv("SERVICES_FILE", "").(string)
|
||||
servicesEnv := utils.Params.GetString("SERVICES_FILE")
|
||||
if servicesEnv == "" {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -42,7 +42,10 @@ func setDefaults() {
|
|||
Params.SetDefault("STATPING_DIR", Directory)
|
||||
Params.SetDefault("GO_ENV", "")
|
||||
Params.SetDefault("DISABLE_LOGS", false)
|
||||
Params.SetDefault("USE_ASSETS", false)
|
||||
Params.SetDefault("BASE_PATH", "")
|
||||
Params.SetDefault("ADMIN_USER", "admin")
|
||||
Params.SetDefault("ADMIN_PASSWORD", "admin")
|
||||
Params.SetDefault("MAX_OPEN_CONN", 25)
|
||||
Params.SetDefault("MAX_IDLE_CONN", 25)
|
||||
Params.SetDefault("MAX_LIFE_CONN", 5*time.Minute)
|
||||
|
@ -51,6 +54,8 @@ func setDefaults() {
|
|||
Params.SetDefault("ALLOW_REPORTS", false)
|
||||
Params.SetDefault("POSTGRES_SSLMODE", "disable")
|
||||
Params.SetDefault("SASS", "sass")
|
||||
Params.SetDefault("REMOVE_AFTER", 2160*time.Hour)
|
||||
Params.SetDefault("CLEANUP_INTERVAL", 1*time.Hour)
|
||||
|
||||
dbConn := Params.GetString("DB_CONN")
|
||||
dbInt := Params.GetInt("DB_PORT")
|
||||
|
|
|
@ -38,9 +38,9 @@ func SentryInit(v *string, allow bool) {
|
|||
}
|
||||
version = *v
|
||||
}
|
||||
goEnv := Getenv("GO_ENV", "production").(string)
|
||||
allowReports := Getenv("ALLOW_REPORTS", false).(bool)
|
||||
if allowReports || allow {
|
||||
goEnv := Params.GetString("GO_ENV")
|
||||
allowReports := Params.GetBool("ALLOW_REPORTS")
|
||||
if allowReports || allow || goEnv == "test" {
|
||||
if err := sentry.Init(sentry.ClientOptions{
|
||||
Dsn: errorReporter,
|
||||
Environment: goEnv,
|
||||
|
|
|
@ -47,12 +47,6 @@ func NotNumber(val string) bool {
|
|||
return err != nil
|
||||
}
|
||||
|
||||
func GetenvAs(key string, defaultValue interface{}) *env {
|
||||
return &env{
|
||||
data: Getenv(key, defaultValue),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *env) Duration() time.Duration {
|
||||
t, err := time.ParseDuration(e.data.(string))
|
||||
if err != nil {
|
||||
|
@ -61,26 +55,6 @@ func (e *env) Duration() time.Duration {
|
|||
return t
|
||||
}
|
||||
|
||||
func Getenv(key string, defaultValue interface{}) interface{} {
|
||||
if defaultValue != nil {
|
||||
Params.SetDefault(key, defaultValue)
|
||||
}
|
||||
val := Params.Get(key)
|
||||
if val != nil {
|
||||
switch val.(type) {
|
||||
case int, int64:
|
||||
return Params.GetInt(key)
|
||||
case time.Duration:
|
||||
return Params.GetDuration(key)
|
||||
case bool:
|
||||
return Params.GetBool(key)
|
||||
default:
|
||||
return val
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// ToInt converts a int to a string
|
||||
func ToInt(s interface{}) int64 {
|
||||
switch v := s.(type) {
|
||||
|
|
Loading…
Reference in New Issue