all repos — weimar @ a213da87e3a6d37de1c358472e176aaf8835b995

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	BehindProxy  bool `mapstructure:"behind_proxy"`
17}
18
19func (s ServerConfig) SecureCookie() bool {
20	return s.BehindProxy
21}
22
23type DatabaseConfig struct {
24	Path string
25}
26
27type StorageConfig struct {
28	Path string
29}
30
31type UploadConfig struct {
32	MaxSizeMB           int `mapstructure:"max_size_mb"`
33	RateLimitPerMinute  int `mapstructure:"rate_limit_per_minute"`
34}
35
36type AuthConfig struct {
37	AllowRegistration   bool `mapstructure:"allow_registration"`
38	RequireAuthForBrowse bool `mapstructure:"require_auth_for_browse"`
39}
40
41func FromViper() Config {
42	return Config{
43		Server: ServerConfig{
44			Host:        viper.GetString("server.host"),
45			Port:        viper.GetInt("server.port"),
46			BehindProxy: viper.GetBool("server.behind_proxy"),
47		},
48		Database: DatabaseConfig{
49			Path: viper.GetString("database.path"),
50		},
51		Storage: StorageConfig{
52			Path: viper.GetString("storage.path"),
53		},
54		Upload: UploadConfig{
55			MaxSizeMB:          viper.GetInt("upload.max_size_mb"),
56			RateLimitPerMinute: viper.GetInt("upload.rate_limit_per_minute"),
57		},
58		Auth: AuthConfig{
59			AllowRegistration:   viper.GetBool("auth.allow_registration"),
60			RequireAuthForBrowse: viper.GetBool("auth.require_auth_for_browse"),
61		},
62	}
63}