Diffstat (limited to 'config')
| -rw-r--r-- | config/config-local-unix.sample.json | 40 | ||||
| -rw-r--r-- | config/config.go | 77 | ||||
| -rw-r--r-- | config/config.json (renamed from config/config-b2.sample.json) | 2 |
3 files changed, 17 insertions, 102 deletions
diff --git a/config/config-local-unix.sample.json b/config/config-local-unix.sample.json deleted file mode 100644 index 637a05a..0000000 --- a/config/config-local-unix.sample.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "ForceRewrite": false, - "MaxConcurrentJobs": 4, - "LogLevel": "debug", - "Input": { - "Storage": { - "Type": "local-unix", - "Config": { - "MaxDepth": 3, - "Path": "/tmp/thumbnailing/full/" - } - }, - "KnownExtensions": [ - "jpg", - "jpeg", - "png" - ] - }, - "Converter": { - "Type": "webp", - "Config": { - "Quality": 80, - "Size": { - "MaxWidth": 800, - "MaxHeight": 0 - } - } - }, - "Output": { - "Storage": { - "Type": "local-unix", - "Config": { - "Path": "/tmp/thumbnailing/thumbnails/", - "DirPermissionMode": "0755", - "FilePermissionMode": "0644", - "AttributesImplementation": "xattr" - } - } - } -}
\ No newline at end of file diff --git a/config/config.go b/config/config.go index d2b7072..3ca8f84 100644 --- a/config/config.go +++ b/config/config.go @@ -19,16 +19,16 @@ type Config struct { } type InputConfig struct { - Storage InputStorageConfig `json:"Storage" validate:"required"` - KnownExtensions []string `json:"KnownExtensions" validate:"required,min=0,dive,min=1"` + Storage StorageConfig `json:"Storage" validate:"required"` + KnownExtensions []string `json:"KnownExtensions" validate:"required,min=0,dive,min=1"` } -type InputStorageConfig struct { - Type string `json:"Type" validate:"required,oneof=b2 local-unix"` +type StorageConfig struct { + Type string `json:"Type" validate:"required,oneof=b2 local"` Config any `json:"Config" validate:"required"` } -func (sc *InputStorageConfig) UnmarshalJSON(data []byte) error { +func (sc *StorageConfig) UnmarshalJSON(data []byte) error { var tmp struct { Type string `json:"Type"` Config json.RawMessage `json:"Config"` @@ -47,49 +47,12 @@ func (sc *InputStorageConfig) UnmarshalJSON(data []byte) error { return fmt.Errorf("unmarshal B2Config: %w", err) } sc.Config = &b2Config - case "local-unix": - var localUnixConfig InputLocalUnixConfig - if err := json.Unmarshal(tmp.Config, &localUnixConfig); err != nil { - return fmt.Errorf("unmarshal LocalUnixConfig: %w", err) + case "local": + var localConfig LocalConfig + if err := json.Unmarshal(tmp.Config, &localConfig); err != nil { + return fmt.Errorf("unmarshal LocalConfig: %w", err) } - sc.Config = &localUnixConfig - default: - return fmt.Errorf("unsupported storage type: %s", tmp.Type) - } - - return nil -} - -type OutputStorageConfig struct { - Type string `json:"Type" validate:"required,oneof=b2 local-unix"` - Config any `json:"Config" validate:"required"` -} - -func (sc *OutputStorageConfig) 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 - } - - sc.Type = tmp.Type - - switch tmp.Type { - case "b2": - var b2Config B2Config - if err := json.Unmarshal(tmp.Config, &b2Config); err != nil { - return fmt.Errorf("unmarshal B2Config: %w", err) - } - sc.Config = &b2Config - case "local-unix": - var localUnixConfig OutputLocalUnixConfig - if err := json.Unmarshal(tmp.Config, &localUnixConfig); err != nil { - return fmt.Errorf("unmarshal LocalUnixConfig: %w", err) - } - sc.Config = &localUnixConfig + sc.Config = &localConfig default: return fmt.Errorf("unsupported storage type: %s", tmp.Type) } @@ -105,20 +68,8 @@ type B2Config struct { ApplicationKey string `json:"ApplicationKey"` } -type InputLocalUnixConfig struct { - MaxDepth int `json:"MaxDepth" validate:"required,min=0"` - Path string `json:"Path" validate:"required,min=1"` -} - -type OutputConfig struct { - Storage OutputStorageConfig `json:"Storage" validate:"required"` -} - -type OutputLocalUnixConfig struct { - Path string `json:"Path" validate:"required,min=1"` - DirPermissionMode string `json:"DirPermissionMode" validate:"required,min=3"` - FilePermissionMode string `json:"FilePermissionMode" validate:"required,min=3"` - AttributesImplementation string `json:"AttributesImplementation" validate:"required,oneof=xattr none"` +type LocalConfig struct { + Path string `json:"Path" validate:"required,min=1"` } type ConverterConfig struct { @@ -162,6 +113,10 @@ type SizeConfig struct { 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-b2.sample.json b/config/config.json index d3d772e..db4ddd4 100644 --- a/config/config-b2.sample.json +++ b/config/config.json @@ -41,4 +41,4 @@ } } } -}
\ No newline at end of file +} |