feat: implementar webapp app_compartir con visor universal, auth y purga 24h para guest
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
BaseURL string
|
||||
DataDir string
|
||||
UploadDir string
|
||||
DBPath string
|
||||
SessionSecret string
|
||||
WebControlURL string
|
||||
GoogleClientID string
|
||||
GoogleClientSecret string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
loadDotEnv(".env")
|
||||
|
||||
port := getEnv("PORT", "8085")
|
||||
baseURL := getEnv("BASE_URL", "http://localhost:"+port)
|
||||
dataDir := getEnv("DATA_DIR", "./data")
|
||||
uploadDir := dataDir + "/uploads"
|
||||
dbPath := dataDir + "/compartir.db"
|
||||
|
||||
return &Config{
|
||||
Port: port,
|
||||
BaseURL: strings.TrimRight(baseURL, "/"),
|
||||
DataDir: dataDir,
|
||||
UploadDir: uploadDir,
|
||||
DBPath: dbPath,
|
||||
SessionSecret: getEnv("SESSION_SECRET", "super-secret-compartir-key-2026"),
|
||||
WebControlURL: getEnv("WEBCONTROL_API_URL", "https://api.siax-system.net"),
|
||||
GoogleClientID: getEnv("GOOGLE_CLIENT_ID", ""),
|
||||
GoogleClientSecret: getEnv("GOOGLE_CLIENT_SECRET", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if val := os.Getenv(key); val != "" {
|
||||
return val
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func loadDotEnv(filepath string) {
|
||||
file, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) == 2 {
|
||||
k := strings.TrimSpace(parts[0])
|
||||
v := strings.Trim(strings.TrimSpace(parts[1]), `"'`)
|
||||
if os.Getenv(k) == "" {
|
||||
os.Setenv(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user