Skip to content
Snippets Groups Projects
Commit 31bf600d authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Improved config unmarshaling

parent 469bf4cc
No related branches found
No related tags found
No related merge requests found
......@@ -67,16 +67,7 @@ func processImage(config *Config, client *redis.Client, value string) {
}
func main() {
config := Config{}
json.Unmarshal([]byte(os.Getenv("IK8R_SIZES")), &config.Sizes)
json.Unmarshal([]byte(os.Getenv("IK8R_QUALITY")), &config.Quality)
config.SourceFolder = os.Getenv("IK8R_SOURCE_FOLDER")
config.TargetFolder = os.Getenv("IK8R_TARGET_FOLDER")
config.Redis.Address = os.Getenv("IK8R_REDIS_ADDRESS")
config.Redis.Password = os.Getenv("IK8R_REDIS_PASSWORD")
config.ImageQueue = os.Getenv("IK8R_REDIS_IMAGE_QUEUE")
config.ResultChannel = os.Getenv("IK8R_REDIS_RESULT_CHANNEL")
config := NewConfigFromEnv()
imagick.Initialize()
defer imagick.Terminate()
......
package main
import (
"os"
"encoding/json"
)
type Image struct {
Id string `json:"id"`
MimeType string `json:"mime_type"`
......@@ -37,12 +42,35 @@ type RedisConfig struct {
Password string
}
type DatabaseConfig struct {
Format string
Url string
}
type Config struct {
Sizes []SizeDefinition
Quality Quality
SourceFolder string
TargetFolder string
Redis RedisConfig
Database DatabaseConfig
ImageQueue string
ResultChannel string
}
func NewConfigFromEnv() Config {
config := Config{}
json.Unmarshal([]byte(os.Getenv("IK8R_SIZES")), &config.Sizes)
json.Unmarshal([]byte(os.Getenv("IK8R_QUALITY")), &config.Quality)
config.SourceFolder = os.Getenv("IK8R_SOURCE_FOLDER")
config.TargetFolder = os.Getenv("IK8R_TARGET_FOLDER")
config.Redis.Address = os.Getenv("IK8R_REDIS_ADDRESS")
config.Redis.Password = os.Getenv("IK8R_REDIS_PASSWORD")
config.ImageQueue = os.Getenv("IK8R_REDIS_IMAGE_QUEUE")
config.ResultChannel = os.Getenv("IK8R_REDIS_RESULT_CHANNEL")
config.Database.Format = os.Getenv("IK8R_DATABASE_TYPE")
config.Database.Url = os.Getenv("IK8R_DATABASE_URL")
return config
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment