ajout app
This commit is contained in:
85
Voltaserve/conversion/config/config.go
Normal file
85
Voltaserve/conversion/config/config.go
Normal file
@ -0,0 +1,85 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var config *Config
|
||||
|
||||
func GetConfig() Config {
|
||||
if config == nil {
|
||||
port, err := strconv.Atoi(os.Getenv("PORT"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config = &Config{
|
||||
Port: port,
|
||||
}
|
||||
readURLs(config)
|
||||
readSecurity(config)
|
||||
readS3(config)
|
||||
readLimits(config)
|
||||
}
|
||||
return *config
|
||||
}
|
||||
|
||||
func readURLs(config *Config) {
|
||||
config.APIURL = os.Getenv("API_URL")
|
||||
}
|
||||
|
||||
func readSecurity(config *Config) {
|
||||
config.Security.APIKey = os.Getenv("SECURITY_API_KEY")
|
||||
}
|
||||
|
||||
func readS3(config *Config) {
|
||||
config.S3.URL = os.Getenv("S3_URL")
|
||||
config.S3.AccessKey = os.Getenv("S3_ACCESS_KEY")
|
||||
config.S3.SecretKey = os.Getenv("S3_SECRET_KEY")
|
||||
config.S3.Region = os.Getenv("S3_REGION")
|
||||
if len(os.Getenv("S3_SECURE")) > 0 {
|
||||
v, err := strconv.ParseBool(os.Getenv("S3_SECURE"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config.S3.Secure = v
|
||||
}
|
||||
}
|
||||
|
||||
func readLimits(config *Config) {
|
||||
if len(os.Getenv("LIMITS_EXTERNAL_COMMAND_TIMEOUT_SECONDS")) > 0 {
|
||||
v, err := strconv.ParseInt(os.Getenv("LIMITS_EXTERNAL_COMMAND_TIMEOUT_SECONDS"), 10, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config.Limits.ExternalCommandTimeoutSeconds = int(v)
|
||||
}
|
||||
if len(os.Getenv("LIMITS_FILE_PROCESSING_MAX_SIZE_MB")) > 0 {
|
||||
v, err := strconv.ParseInt(os.Getenv("LIMITS_FILE_PROCESSING_MAX_SIZE_MB"), 10, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config.Limits.FileProcessingMaxSizeMB = int(v)
|
||||
}
|
||||
if len(os.Getenv("LIMITS_IMAGE_PREVIEW_MAX_WIDTH")) > 0 {
|
||||
v, err := strconv.ParseInt(os.Getenv("LIMITS_IMAGE_PREVIEW_MAX_WIDTH"), 10, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config.Limits.ImagePreviewMaxWidth = int(v)
|
||||
}
|
||||
if len(os.Getenv("LIMITS_IMAGE_PREVIEW_MAX_HEIGHT")) > 0 {
|
||||
v, err := strconv.ParseInt(os.Getenv("LIMITS_IMAGE_PREVIEW_MAX_HEIGHT"), 10, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config.Limits.ImagePreviewMaxHeight = int(v)
|
||||
}
|
||||
if len(os.Getenv("LIMITS_LANGUAGE_SCORE_THRESHOLD")) > 0 {
|
||||
v, err := strconv.ParseFloat(os.Getenv("LIMITS_LANGUAGE_SCORE_THRESHOLD"), 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
config.Limits.LanguageScoreThreshold = v
|
||||
}
|
||||
}
|
29
Voltaserve/conversion/config/types.go
Normal file
29
Voltaserve/conversion/config/types.go
Normal file
@ -0,0 +1,29 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
Port int
|
||||
APIURL string
|
||||
Security SecurityConfig
|
||||
Limits LimitsConfig
|
||||
S3 S3Config
|
||||
}
|
||||
|
||||
type SecurityConfig struct {
|
||||
APIKey string `json:"api_key"`
|
||||
}
|
||||
|
||||
type LimitsConfig struct {
|
||||
ExternalCommandTimeoutSeconds int
|
||||
FileProcessingMaxSizeMB int
|
||||
ImagePreviewMaxWidth int
|
||||
ImagePreviewMaxHeight int
|
||||
LanguageScoreThreshold float64
|
||||
}
|
||||
|
||||
type S3Config struct {
|
||||
URL string
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
Region string
|
||||
Secure bool
|
||||
}
|
Reference in New Issue
Block a user