59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type Environment struct {
|
|
// Items made for the presentation of ORBITS
|
|
Version string
|
|
Codename string
|
|
LogLevel string
|
|
|
|
// Items made for the configuration of the server parts
|
|
DataDirectory string
|
|
ContentDirectory string
|
|
Hostname string
|
|
Port int
|
|
AuthenticationEnabled bool
|
|
|
|
// Items made for the server watchdog
|
|
WatchdogEnabled bool
|
|
WatchdogInterval int
|
|
WatchdogSyncMode string
|
|
}
|
|
|
|
func GrabEnvironment() Environment {
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
cwd = "."
|
|
}
|
|
|
|
fbBase := filepath.Join(cwd, "data")
|
|
fbContent := filepath.Join(fbBase, "content")
|
|
|
|
return Environment{
|
|
// Basic server configuration
|
|
Version: safeStringGrab("VERSION", "0.0.1"),
|
|
Codename: safeStringGrab("CODENAME", "Magical Anomaly"),
|
|
LogLevel: safeStringGrab("LOG_LEVEL", "debug"),
|
|
|
|
// GIN API configuration
|
|
DataDirectory: safeStringGrab("DATA_DIR", fbBase),
|
|
ContentDirectory: safeStringGrab("CONTENT_DIR", fbContent),
|
|
Hostname: safeStringGrab("HOSTNAME", "0.0.0.0"),
|
|
Port: safeIntGrab("PORT", 8080),
|
|
AuthenticationEnabled: safeBoolGrab("AUTH_ENABLED", true),
|
|
|
|
// watchdog configuration
|
|
// watchdog is the integrity checker/steward
|
|
WatchdogEnabled: safeBoolGrab("WATCHDOG_ENABLED", true),
|
|
WatchdogInterval: safeIntGrab("WATCHDOG_INTERVAL", 60),
|
|
// sync: sync local files to the database, for example when you want to allow local inserting files which then get added to the database
|
|
// strict: make the database leading, this is when you only allow API uploads to be registered, and remove orphaned filesystem files
|
|
// dry: do nothing
|
|
WatchdogSyncMode: safeStringGrab("WATCHDOG_SYNC_MODE", "strict"),
|
|
}
|
|
}
|