generated from akmamun/chi-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
42 lines (37 loc) · 991 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
package main
import (
"github.com/spf13/viper"
"go-fication/config"
"go-fication/infra/database"
"go-fication/infra/logger"
"go-fication/migrations"
"go-fication/routers"
"net/http"
"time"
)
func main() {
viper.SetDefault("SERVER_TIMEZONE", "Asia/Dhaka")
loc, _ := time.LoadLocation(viper.GetString("SERVER_TIMEZONE"))
time.Local = loc
if err := config.SetupConfig(); err != nil {
logger.Error("%v", err)
}
logLevel := viper.GetString("LOG_LEVEL")
logger.SetLogLevel(logLevel)
db, err := database.DBConnection(config.GetDNSConfig())
if err != nil {
logger.Fatal("%v", err)
}
//later remove auto migration
migrations.Migrate(db)
router := routers.SetupRoute(db)
server := http.Server{
Addr: config.ServerConfig(),
Handler: router,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 30 * time.Second,
ReadHeaderTimeout: 2 * time.Second,
}
logger.Fatal("%v", server.ListenAndServe())
}