forked from zubroide/go-api-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (46 loc) · 999 Bytes
/
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
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/zubroide/go-api-boilerplate/command"
"github.com/zubroide/go-api-boilerplate/dic"
"fmt"
"github.com/getsentry/raven-go"
"github.com/spf13/viper"
"os"
)
func readConfig() {
var err error
viper.SetConfigFile("base.env")
viper.SetConfigType("props")
err = viper.ReadInConfig()
if err != nil {
fmt.Println(err)
return
}
if _, err := os.Stat(".env"); os.IsNotExist(err) {
fmt.Println("WARNING: file .env not found")
} else {
viper.SetConfigFile(".env")
viper.SetConfigType("props")
err = viper.MergeInConfig()
if err != nil {
fmt.Println(err)
return
}
}
// Override config parameters from environment variables if specified
for _, key := range viper.AllKeys() {
viper.BindEnv(key)
}
}
func main() {
readConfig()
dic.InitContainer()
client := dic.Container.Get(dic.RavenClient).(*raven.Client)
if client != nil {
client.CapturePanicAndWait(func() {
command.Execute()
}, nil)
} else {
command.Execute()
}
}