summaryrefslogtreecommitdiffci
path: root/config
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/config.go79
1 files changed, 2 insertions, 77 deletions
diff --git a/config/config.go b/config/config.go
index e48a28b..eb4a91d 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,8 +1,6 @@
package config
import (
- "encoding/json"
- "fmt"
"log/slog"
"os"
@@ -27,72 +25,8 @@ type BlogPagesConfig struct {
}
type StorageConfig struct {
- Type string `json:"type" yaml:"type,oneof=b2 s3"`
- Config any `json:"Config" yaml:"config" validate:"required"`
-}
-
-func (sc *StorageConfig) 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 "s3":
- var s3Config S3Config
- if err := json.Unmarshal(tmp.Config, &s3Config); err != nil {
- return fmt.Errorf("unmarshal S3Config: %w", err)
- }
- sc.Config = &s3Config
- default:
- return fmt.Errorf("unsupported storage type: %s", tmp.Type)
- }
-
- return nil
-}
-
-func (sc *StorageConfig) UnmarshalYAML(value *yaml.Node) error {
- var tmp struct {
- Type string `yaml:"type"`
- Config yaml.Node `yaml:"config"`
- }
-
- if err := value.Decode(&tmp); err != nil {
- return err
- }
-
- sc.Type = tmp.Type
-
- switch tmp.Type {
- case "b2":
- var b2Config B2Config
- if err := tmp.Config.Decode(&b2Config); err != nil {
- return fmt.Errorf("unmarshal B2Config: %w", err)
- }
- sc.Config = &b2Config
- case "s3":
- var s3Config S3Config
- if err := tmp.Config.Decode(&s3Config); err != nil {
- return fmt.Errorf("unmarshal S3Config: %w", err)
- }
- sc.Config = &s3Config
- default:
- return fmt.Errorf("unsupported storage type: %s", tmp.Type)
- }
-
- return nil
+ Type string `json:"type" yaml:"type"`
+ Config B2Config `json:"Config" yaml:"config" validate:"required"`
}
type B2Config struct {
@@ -103,15 +37,6 @@ type B2Config struct {
ApplicationKey string `json:"ApplicationKey" yaml:"applicationKey"`
}
-type S3Config struct {
- BucketName string `json:"BucketName" yaml:"bucketName" validate:"required,min=1"`
- Region string `json:"Region" yaml:"region" validate:"required,min=1"`
- Prefix string `json:"Prefix" yaml:"prefix"`
- Endpoint string `json:"Endpoint" yaml:"endpoint" validate:"required,url"`
- AccessKeyID string `json:"AccessKeyID" yaml:"accessKeyID"`
- SecretAccessKey string `json:"SecretAccessKey" yaml:"secretAccessKey"`
-}
-
type FactGiverConfig struct {
Storage StorageConfig `json:"Storage" yaml:"storage" validate:"required"`
FactsFileName string `json:"FactsFileName" yaml:"factsFileName" validate:"required"`