feat: make watchdog itself configurable
This commit is contained in:
@@ -15,6 +15,7 @@ type Environment struct {
|
||||
ContentDirectory string
|
||||
Hostname string
|
||||
Port int
|
||||
WatchdogEnabled bool
|
||||
WatchdogInterval int
|
||||
WatchdogSyncMode string
|
||||
}
|
||||
@@ -46,6 +47,15 @@ func safeIntGrab(key string, fallback int) int {
|
||||
return fallback
|
||||
}
|
||||
|
||||
func safeBoolGrab(key string, fallback bool) bool {
|
||||
if v, ok := os.LookupEnv(key); ok {
|
||||
if b, err := strconv.ParseBool(v); err == nil {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func safeSyncModeGrab(key, fallback string) string {
|
||||
if v, ok := os.LookupEnv(key); ok {
|
||||
if slices.Contains(validSyncModes, v) {
|
||||
@@ -66,12 +76,19 @@ func GrabEnvironment() Environment {
|
||||
fbContent := filepath.Join(fbBase, "content")
|
||||
|
||||
return Environment{
|
||||
Version: safeStringGrab("VERSION", "0.0.1"),
|
||||
Codename: safeStringGrab("CODENAME", "Magical Anomaly"),
|
||||
// Basic server configuration
|
||||
Version: safeStringGrab("VERSION", "0.0.1"),
|
||||
Codename: safeStringGrab("CODENAME", "Magical Anomaly"),
|
||||
|
||||
// GIN API configuration
|
||||
DataDirectory: safeStringGrab("DATA_DIR", fbBase),
|
||||
ContentDirectory: safeStringGrab("CONTENT_DIR", fbContent),
|
||||
Hostname: safeStringGrab("HOSTNAME", "0.0.0.0"),
|
||||
Port: safeIntGrab("PORT", 8080),
|
||||
|
||||
// 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
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
)
|
||||
|
||||
func HashReader(r io.Reader) (string, error) {
|
||||
@@ -19,23 +17,3 @@ func HashReader(r io.Reader) (string, error) {
|
||||
// alternatively return in base64
|
||||
//return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
func HashUpload(fileHeader *multipart.FileHeader) (string, error) {
|
||||
stream, err := fileHeader.Open()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
return HashReader(stream)
|
||||
}
|
||||
|
||||
func HashFile(path string) (string, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
return HashReader(file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user