all repos — weimar @ afea02cbeb79ac199b088f364eeadd21c25e0ca2

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