feat: add working watchdog cycle
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package utility
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Environment struct {
|
||||
Version string
|
||||
Codename string
|
||||
DataDirectory string
|
||||
ContentDirectory string
|
||||
Hostname string
|
||||
Port int
|
||||
WatchInterval int
|
||||
}
|
||||
|
||||
// part of environment checking
|
||||
func safeStringGrab(key, fallback string) string {
|
||||
if v, ok := os.LookupEnv(key); ok {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func safeIntGrab(key string, fallback int) int {
|
||||
if v, ok := os.LookupEnv(key); ok {
|
||||
if i, err := strconv.Atoi(v); err == nil {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func GrabEnvironment() Environment {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
cwd = "."
|
||||
}
|
||||
|
||||
fbBase := filepath.Join(cwd, "data")
|
||||
fbContent := filepath.Join(fbBase, "content")
|
||||
|
||||
return Environment{
|
||||
Version: safeStringGrab("VERSION", "0.0.1"),
|
||||
Codename: safeStringGrab("CODENAME", "Magical Anomaly"),
|
||||
DataDirectory: safeStringGrab("DATA_DIR", fbBase),
|
||||
ContentDirectory: safeStringGrab("CONTENT_DIR", fbContent),
|
||||
Hostname: safeStringGrab("HOSTNAME", "0.0.0.0"),
|
||||
|
||||
Port: safeIntGrab("PORT", 8080),
|
||||
WatchInterval: safeIntGrab("WATCHDOG_INTERVAL", 60),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user