all repos — weimar @ 8d72190a752e3e1eaff992da40d75e01c6149993

Unnamed repository; edit this file 'description' to name the repository.

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}
34
35func FromViper() Config {
36	return Config{
37		Server: ServerConfig{
38			Host: viper.GetString("server.host"),
39			Port: viper.GetInt("server.port"),
40		},
41		Database: DatabaseConfig{
42			Path: viper.GetString("database.path"),
43		},
44		Storage: StorageConfig{
45			Path: viper.GetString("storage.path"),
46		},
47		Upload: UploadConfig{
48			MaxSizeMB:          viper.GetInt("upload.max_size_mb"),
49			RateLimitPerMinute: viper.GetInt("upload.rate_limit_per_minute"),
50		},
51		Auth: AuthConfig{
52			AllowRegistration: viper.GetBool("auth.allow_registration"),
53		},
54	}
55}