-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
46 lines (38 loc) · 1.03 KB
/
server.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/asvins/common_db/postgres"
"github.com/asvins/common_io"
"github.com/asvins/utils/config"
"github.com/jinzhu/gorm"
"github.com/unrolled/render"
)
var (
ServerConfig *Config = new(Config)
rend *render.Render = render.New() // used to write into responses
db *gorm.DB
producer *common_io.Producer
consumer *common_io.Consumer
)
// function that will run before main
func init() {
fmt.Println("[INFO] Initializing server")
err := config.Load("warehouse_config.gcfg", ServerConfig)
if err != nil {
log.Fatal(err)
}
DatabaseConfig := postgres.NewConfig(ServerConfig.Database.User, ServerConfig.Database.DbName, ServerConfig.Database.SSLMode)
db = postgres.GetDatabase(DatabaseConfig)
fmt.Println("[INFO] Initialization Done!")
/*
* Common io
*/
setupCommonIo()
}
func main() {
router := DefRoutes()
fmt.Println("[INFO] Server running on port:", ServerConfig.Server.Port)
http.ListenAndServe(":"+ServerConfig.Server.Port, router)
}