82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
"tss-rocks-be/internal/types"
|
|
)
|
|
|
|
type Config struct {
|
|
Database DatabaseConfig `yaml:"database"`
|
|
Server ServerConfig `yaml:"server"`
|
|
JWT JWTConfig `yaml:"jwt"`
|
|
Auth AuthConfig `yaml:"auth"`
|
|
Storage StorageConfig `yaml:"storage"`
|
|
Logging LoggingConfig `yaml:"logging"`
|
|
RateLimit types.RateLimitConfig `yaml:"rate_limit"`
|
|
AccessLog types.AccessLogConfig `yaml:"access_log"`
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Driver string `yaml:"driver"`
|
|
DSN string `yaml:"dsn"`
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Port int `yaml:"port"`
|
|
Host string `yaml:"host"`
|
|
}
|
|
|
|
type JWTConfig struct {
|
|
Secret string `yaml:"secret"`
|
|
Expiration string `yaml:"expiration"`
|
|
}
|
|
|
|
type AuthConfig struct {
|
|
Registration struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
Message string `yaml:"message"`
|
|
} `yaml:"registration"`
|
|
}
|
|
|
|
type LoggingConfig struct {
|
|
Level string `yaml:"level"`
|
|
Format string `yaml:"format"`
|
|
}
|
|
|
|
type StorageConfig struct {
|
|
Type string `yaml:"type"`
|
|
Local LocalStorage `yaml:"local"`
|
|
S3 S3Storage `yaml:"s3"`
|
|
Upload types.UploadConfig `yaml:"upload"`
|
|
}
|
|
|
|
type LocalStorage struct {
|
|
RootDir string `yaml:"root_dir"`
|
|
}
|
|
|
|
type S3Storage struct {
|
|
Region string `yaml:"region"`
|
|
Bucket string `yaml:"bucket"`
|
|
AccessKeyID string `yaml:"access_key_id"`
|
|
SecretAccessKey string `yaml:"secret_access_key"`
|
|
Endpoint string `yaml:"endpoint"`
|
|
CustomURL string `yaml:"custom_url"`
|
|
ProxyS3 bool `yaml:"proxy_s3"`
|
|
}
|
|
|
|
// Load loads configuration from a YAML file
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|