-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (41 loc) · 1.04 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
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"github.com/spf13/viper"
"github.com/zidni722/golang-restfull/bootstrap"
"github.com/zidni722/golang-restfull/config"
"github.com/zidni722/golang-restfull/routes"
)
func newApp() *bootstrap.Bootstrapper {
app := bootstrap.New(viper.GetString("app.name"), viper.GetString("app.owner"))
app.Bootstrap()
return app
}
func readConfig() {
viper.SetConfigName("env")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
fmt.Println("Config file not found...")
} else {
viper.SetEnvPrefix("product-api")
viper.AllowEmptyEnv(true)
viper.AutomaticEnv()
}
}
func setupRoute(app *bootstrap.Bootstrapper, cfg *config.Configuration) {
route := routes.NewRoute(cfg)
app.Configure(route.Configure)
}
func main() {
readConfig()
app := newApp()
port := viper.GetString("app.server_port")
cfg := config.New(app.Application)
cfg.SetupLog()
cfg.SetupDatabase()
setupRoute(app, cfg)
fmt.Print("Application is running on port :" + port)
app.Listen(":" + port)
defer cfg.Database.DB.Close()
}