Total Lines | 82 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package config |
||
2 | |||
3 | import ( |
||
4 | "github.com/memnix/memnix-rest/pkg/oauth" |
||
5 | "github.com/spf13/viper" |
||
6 | ) |
||
7 | |||
8 | // Config holds the configuration for the application. |
||
9 | type Config struct { |
||
10 | Server ServerConfig |
||
11 | Database DatabaseConfig |
||
12 | Redis RedisConfig |
||
13 | Log LogConfig |
||
14 | Auth AuthConfig |
||
15 | Sentry SentryConfig |
||
16 | } |
||
17 | |||
18 | // SentryConfig holds the configuration for the sentry client. |
||
19 | type SentryConfig struct { |
||
20 | Debug bool |
||
21 | Environment string |
||
22 | Release string |
||
23 | TracesSampleRate float64 |
||
24 | ProfilesSampleRate float64 |
||
25 | DSN string |
||
26 | } |
||
27 | |||
28 | // ServerConfig holds the configuration for the server. |
||
29 | type ServerConfig struct { |
||
30 | Port string |
||
31 | AppVersion string |
||
32 | JaegerURL string |
||
33 | Host string |
||
34 | FrontendURL string |
||
35 | } |
||
36 | |||
37 | // DatabaseConfig holds the configuration for the database. |
||
38 | type DatabaseConfig struct { |
||
39 | DSN string |
||
40 | } |
||
41 | |||
42 | // RedisConfig holds the configuration for the redis client. |
||
43 | type RedisConfig struct { |
||
44 | Addr string |
||
45 | Password string |
||
46 | MinIdleConns int |
||
47 | PoolSize int |
||
48 | PoolTimeout int |
||
49 | } |
||
50 | |||
51 | // LogConfig holds the configuration for the logger. |
||
52 | type LogConfig struct { |
||
53 | Level string |
||
54 | } |
||
55 | |||
56 | // AuthConfig holds the configuration for the authentication. |
||
57 | type AuthConfig struct { |
||
58 | JWTSecret string |
||
59 | JWTHeaderLen int |
||
60 | JWTExpiration int |
||
61 | Discord oauth.DiscordConfig |
||
62 | Github oauth.GithubConfig |
||
63 | Bcryptcost int |
||
64 | } |
||
65 | |||
66 | // LoadConfig loads the configuration from a file. |
||
67 | func LoadConfig(filename string) (*Config, error) { |
||
68 | v := viper.New() |
||
69 | v.SetConfigName(filename) |
||
70 | v.AddConfigPath(".") |
||
71 | v.AutomaticEnv() |
||
72 | |||
73 | if err := v.ReadInConfig(); err != nil { |
||
74 | return nil, err |
||
75 | } |
||
76 | |||
77 | var c Config |
||
78 | if err := v.Unmarshal(&c); err != nil { |
||
79 | return nil, err |
||
80 | } |
||
81 | |||
82 | return &c, nil |
||
83 | } |
||
84 |