internal/config/config.go (view raw)
1package config
2
3import "github.com/spf13/viper"
4
5type Config struct {
6 Server ServerConfig
7 Database DatabaseConfig
8 Storage StorageConfig
9 Upload UploadConfig
10 Auth AuthConfig
11}
12
13type ServerConfig struct {
14 Host string
15 Port int
16}
17
18type DatabaseConfig struct {
19 Path string
20}
21
22type StorageConfig struct {
23 Path string
24}
25
26type UploadConfig struct {
27 MaxSizeMB int `mapstructure:"max_size_mb"`
28 RateLimitPerMinute int `mapstructure:"rate_limit_per_minute"`
29}
30
31type AuthConfig struct {
32 AllowRegistration bool `mapstructure:"allow_registration"`
33 RequireAuthForBrowse bool `mapstructure:"require_auth_for_browse"`
34}
35
36func FromViper() Config {
37 return Config{
38 Server: ServerConfig{
39 Host: viper.GetString("server.host"),
40 Port: viper.GetInt("server.port"),
41 },
42 Database: DatabaseConfig{
43 Path: viper.GetString("database.path"),
44 },
45 Storage: StorageConfig{
46 Path: viper.GetString("storage.path"),
47 },
48 Upload: UploadConfig{
49 MaxSizeMB: viper.GetInt("upload.max_size_mb"),
50 RateLimitPerMinute: viper.GetInt("upload.rate_limit_per_minute"),
51 },
52 Auth: AuthConfig{
53 AllowRegistration: viper.GetBool("auth.allow_registration"),
54 RequireAuthForBrowse: viper.GetBool("auth.require_auth_for_browse"),
55 },
56 }
57}