-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
44 lines (36 loc) · 1.21 KB
/
main.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
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
viper.SetConfigName("app") // no need to include file extension
viper.AddConfigPath("config") // set the path of your config file
err := viper.ReadInConfig()
if err != nil {
fmt.Println("Config file not found...")
} else {
dev_server := viper.GetString("development.server")
dev_connection_max := viper.GetInt("development.connection_max")
dev_enabled := viper.GetBool("development.enabled")
dev_port := viper.GetInt("development.port")
fmt.Printf("\nDevelopment Config found:\n server = %s\n connection_max = %d\n" +
" enabled = %t\n" +
" port = %d\n",
dev_server,
dev_connection_max,
dev_enabled,
dev_port)
prod_server := viper.GetString("production.server")
prod_connection_max := viper.GetInt("production.connection_max")
prod_enabled := viper.GetBool("production.enabled")
prod_port := viper.GetInt("production.port")
fmt.Printf("\nProduction Config found:\n server = %s\n connection_max = %d\n" +
" enabled = %t\n" +
" port = %d\n",
prod_server,
prod_connection_max,
prod_enabled,
prod_port)
}
}