-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig.go
68 lines (54 loc) · 1.91 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package config
import (
"os"
"github.com/spf13/viper"
)
const (
AppEnvProd = "prod" // prod environment
AppEnvDev = "dev" // dev environment
AppEnvTest = "test" // test environment
DefaultAppName = "app" // default application name
DefaultAppVersion = "unknown" // default application version
)
// Config allows to access the application configuration, and inherits of all [Viper] features.
//
// [Viper]: https://github.com/spf13/viper
type Config struct {
*viper.Viper
}
// GetEnvVar returns the value of an env var.
func (c *Config) GetEnvVar(envVar string) string {
return os.Getenv(envVar)
}
// AppName returns the configured application name (from config field app.name or env var APP_NAME).
func (c *Config) AppName() string {
return c.GetString("app.name")
}
// AppDescription returns the configured application description (from config field app.description or env var APP_DESCRIPTION).
func (c *Config) AppDescription() string {
return c.GetString("app.description")
}
// AppEnv returns the configured application environment (from config field app.env or env var APP_ENV).
func (c *Config) AppEnv() string {
return c.GetString("app.env")
}
// AppVersion returns the configured application version (from config field app.version or env var APP_VERSION).
func (c *Config) AppVersion() string {
return c.GetString("app.version")
}
// AppDebug returns if the application debug mode is enabled (from config field app.debug or env var APP_DEBUG).
func (c *Config) AppDebug() bool {
return c.GetBool("app.debug")
}
// IsProdEnv returns if the application is running in prod mode.
func (c *Config) IsProdEnv() bool {
return c.AppEnv() == AppEnvProd
}
// IsDevEnv returns if the application is running in dev mode.
func (c *Config) IsDevEnv() bool {
return c.AppEnv() == AppEnvDev
}
// IsTestEnv returns if the application is running in test mode.
func (c *Config) IsTestEnv() bool {
return c.AppEnv() == AppEnvTest
}