Restructured project
- backend moved to backend directory - added and initialized frontend with vue - moved infrastructure files to infra directory
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
RunMode RunMode
|
||||
DebugMode bool
|
||||
BotToken string
|
||||
|
||||
DBConnectionString string
|
||||
|
||||
OCRTokenPath string
|
||||
|
||||
TelegramApi string
|
||||
|
||||
APIPort string
|
||||
APIHost string
|
||||
APISecret string
|
||||
OpenAPIEnabled bool
|
||||
OpenAPIEndpoint string
|
||||
}
|
||||
|
||||
func Load() (Config, error) {
|
||||
_ = godotenv.Load()
|
||||
var warnings []string
|
||||
|
||||
mode := os.Getenv("RUN_MODE")
|
||||
debugMode := os.Getenv("DEBUG_MODE") == "true"
|
||||
botToken := os.Getenv("BOT_TOKEN")
|
||||
dbConnectionString := os.Getenv("DB_PATH")
|
||||
ocrTokenPath := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
apiPort := os.Getenv("API_PORT")
|
||||
apiHost := os.Getenv("API_HOST")
|
||||
apiSecret := os.Getenv("API_SECRET")
|
||||
openAPIEnabled := os.Getenv("OPEN_API_ENABLED") == "true"
|
||||
openAPIEndpoint := os.Getenv("OPEN_API_ENDPOINT")
|
||||
|
||||
runMode, err := ParseRunMode(mode)
|
||||
if err != nil {
|
||||
warnings = append(warnings, err.Error())
|
||||
}
|
||||
|
||||
if runMode == Bot || runMode == Standalone {
|
||||
if ocrTokenPath == "" {
|
||||
warnings = append(warnings, "Missing required environment variable: GOOGLE_APPLICATION_CREDENTIALS")
|
||||
}
|
||||
if botToken == "" {
|
||||
warnings = append(warnings, "Missing required environment variable: BOT_TOKEN")
|
||||
}
|
||||
}
|
||||
if runMode == API || runMode == Standalone {
|
||||
if apiSecret == "" {
|
||||
warnings = append(warnings, "Missing required environment variable: API_SECRET")
|
||||
}
|
||||
if dbConnectionString == "" {
|
||||
dbConnectionString = "sqlite://data/app.db"
|
||||
}
|
||||
if apiHost == "" {
|
||||
apiHost = "localhost"
|
||||
}
|
||||
if apiPort == "" {
|
||||
apiPort = "8000"
|
||||
}
|
||||
if openAPIEndpoint == "" {
|
||||
openAPIEndpoint = "/docs"
|
||||
}
|
||||
}
|
||||
|
||||
if len(warnings) > 0 {
|
||||
return Config{}, errors.New(strings.Join(warnings, "\n"))
|
||||
}
|
||||
return Config{
|
||||
BotToken: botToken,
|
||||
DBConnectionString: dbConnectionString,
|
||||
OCRTokenPath: ocrTokenPath,
|
||||
DebugMode: debugMode,
|
||||
RunMode: runMode,
|
||||
APIPort: apiPort,
|
||||
APIHost: apiHost,
|
||||
APISecret: apiSecret,
|
||||
OpenAPIEnabled: openAPIEnabled,
|
||||
OpenAPIEndpoint: openAPIEndpoint,
|
||||
TelegramApi: "https://api.telegram.org",
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user