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