mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2025-12-14 04:05:14 +00:00
Add image cache and use struct for config (closes #58)
This commit is contained in:
@@ -1,8 +1,23 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Config map[string]interface{}
|
||||
type config struct {
|
||||
Port string
|
||||
Addr string
|
||||
ImgurId string
|
||||
FiberPrefork bool
|
||||
ImageCache bool
|
||||
CleanupInterval time.Duration
|
||||
CacheDir string
|
||||
Privacy map[string]interface{}
|
||||
}
|
||||
|
||||
var Config config
|
||||
|
||||
func LoadConfig() {
|
||||
port := "3000"
|
||||
@@ -13,11 +28,6 @@ func LoadConfig() {
|
||||
port = os.Getenv("RIMGU_PORT")
|
||||
}
|
||||
|
||||
fiberPrefork := false
|
||||
if os.Getenv("FIBER_PREFORK") == "true" {
|
||||
fiberPrefork = true
|
||||
}
|
||||
|
||||
addr := "0.0.0.0"
|
||||
if os.Getenv("ADDRESS") != "" {
|
||||
addr = os.Getenv("ADDRESS")
|
||||
@@ -34,14 +44,29 @@ func LoadConfig() {
|
||||
imgurId = os.Getenv("RIMGU_IMGUR_CLIENT_ID")
|
||||
}
|
||||
|
||||
Config = map[string]interface{}{
|
||||
"port": port,
|
||||
"addr": addr,
|
||||
"imgurId": imgurId,
|
||||
"fiberPrefork": fiberPrefork,
|
||||
"privacy": map[string]interface{}{
|
||||
"set": os.Getenv("PRIVACY_NOT_COLLECTED") != "",
|
||||
"policy": os.Getenv("PRIVACY_POLICY"),
|
||||
imageCache := os.Getenv("IMAGE_CACHE") == "true"
|
||||
|
||||
cleanupInterval, err := time.ParseDuration(os.Getenv("IMAGE_CACHE_CLEANUP_INTERVAL"))
|
||||
if err != nil && imageCache {
|
||||
log.Fatal("invalid configuration: invalid duration for IMAGE_CACHE_CLEANUP_INTERVAL")
|
||||
}
|
||||
|
||||
cacheDir := os.Getenv("IMAGE_CACHE_DIR")
|
||||
if cacheDir == "" && imageCache {
|
||||
log.Fatal("invalid configuration: no IMAGE_CACHE_DIR")
|
||||
}
|
||||
|
||||
Config = config{
|
||||
Port: port,
|
||||
Addr: addr,
|
||||
ImgurId: imgurId,
|
||||
FiberPrefork: os.Getenv("FIBER_PREFORK") == "true",
|
||||
ImageCache: imageCache,
|
||||
CleanupInterval: cleanupInterval,
|
||||
CacheDir: cacheDir,
|
||||
Privacy: map[string]interface{}{
|
||||
"set": os.Getenv("PRIVACY_NOT_COLLECTED") != "",
|
||||
"policy": os.Getenv("PRIVACY_POLICY"),
|
||||
"message": os.Getenv("PRIVACY_MESSAGE"),
|
||||
"country": os.Getenv("PRIVACY_COUNTRY"),
|
||||
"provider": os.Getenv("PRIVACY_PROVIDER"),
|
||||
|
||||
Reference in New Issue
Block a user