summaryrefslogtreecommitdiff
path: root/config
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/config.go58
-rw-r--r--config/config.json22
2 files changed, 17 insertions, 63 deletions
diff --git a/config/config.go b/config/config.go
index 5df29df..6d37904 100644
--- a/config/config.go
+++ b/config/config.go
@@ -9,14 +9,18 @@ import (
)
type Config struct {
- Input InputConfig `json:"Input" validate:"required"`
- Processor ProcessorConfig `json:"Processor" validate:"required"`
- Output OutputConfig `json:"Output" validate:"required"`
+ Input InputConfig `json:"Input" validate:"required"`
+ Output OutputConfig `json:"Output" validate:"required"`
}
type InputConfig struct {
- Storage StorageConfig `json:"Storage" validate:"required"`
- KnownExtensions []string `json:"KnownExtensions" validate:"required,min=0,dive,min=1"`
+ Storage StorageConfig `json:"Storage" validate:"required"`
+}
+
+type OutputConfig struct {
+ Storage StorageConfig `json:"Storage" validate:"required"`
+ Quality int `json:"Quality" validate:"required,min=1,max=100"`
+ Size SizeConfig `json:"Size" validate:"required"`
}
type StorageConfig struct {
@@ -42,13 +46,13 @@ func (sc *StorageConfig) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(tmp.Config, &b2Config); err != nil {
return fmt.Errorf("unmarshal B2Config: %w", err)
}
- sc.Config = &b2Config
+ sc.Config = b2Config
case "local":
var localConfig LocalConfig
if err := json.Unmarshal(tmp.Config, &localConfig); err != nil {
return fmt.Errorf("unmarshal LocalConfig: %w", err)
}
- sc.Config = &localConfig
+ sc.Config = localConfig
default:
return fmt.Errorf("unsupported storage type: %s", tmp.Type)
}
@@ -68,51 +72,11 @@ type LocalConfig struct {
Path string `json:"Path" validate:"required,min=1"`
}
-type ProcessorConfig struct {
- Type string `json:"Type" validate:"required,oneof=webp"`
- Config any `json:"Config" validate:"required"`
-}
-
-func (pc *ProcessorConfig) UnmarshalJSON(data []byte) error {
- var tmp struct {
- Type string `json:"Type"`
- Config json.RawMessage `json:"Config"`
- }
-
- if err := json.Unmarshal(data, &tmp); err != nil {
- return err
- }
-
- pc.Type = tmp.Type
-
- switch tmp.Type {
- case "webp":
- var webpConfig WebpConfig
- if err := json.Unmarshal(tmp.Config, &webpConfig); err != nil {
- return fmt.Errorf("unmarshal WebpConfig: %w", err)
- }
- pc.Config = &webpConfig
- default:
- return fmt.Errorf("unsupported storage type: %s", tmp.Type)
- }
-
- return nil
-}
-
-type WebpConfig struct {
- Quality int `json:"Quality" validate:"required,min=1,max=100"`
- Size SizeConfig `json:"Size" validate:"required"`
-}
-
type SizeConfig struct {
MaxWidth int `json:"MaxWidth" validate:"required,min=0"`
MaxHeight int `json:"MaxHeight" validate:"required,min=0"`
}
-type OutputConfig struct {
- Storage StorageConfig `json:"Storage" validate:"required"`
-}
-
func LoadConfig(path string, config *Config) error {
fileBytes, err := os.ReadFile(path)
if err != nil {
diff --git a/config/config.json b/config/config.json
index 298a03f..d818107 100644
--- a/config/config.json
+++ b/config/config.json
@@ -9,21 +9,6 @@
"KeyID": "${B2_KEY_ID}",
"ApplicationKey": "${B2_APPLICATION_KEY}"
}
- },
- "KnownExtensions": [
- "jpg",
- "jpeg",
- "png"
- ]
- },
- "Processor": {
- "Type": "webp",
- "Config": {
- "Quality": 80,
- "Size": {
- "MaxWidth": 1280,
- "MaxHeight": 0
- }
}
},
"Output": {
@@ -36,6 +21,11 @@
"KeyID": "${B2_KEY_ID}",
"ApplicationKey": "${B2_APPLICATION_KEY}"
}
+ },
+ "Quality": 80,
+ "Size": {
+ "MaxWidth": 1280,
+ "MaxHeight": 0
}
}
-}
+} \ No newline at end of file