generated from usama28232/authexample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1002 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
package main
import (
"flag"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/usama28232/candid/controllers"
"github.com/usama28232/candid/db"
"github.com/usama28232/candid/logging"
)
func main() {
logger := logging.GetLogger()
logger.Info("*** starting `candid framework` ***")
logger.Info("https://github.com/usama28232/candid")
var port string
flag.StringVar(&port, "port", "3000", "Specifies Application Port")
flag.Parse()
dbconn, dbSErr := db.Init()
logger.Debug(dbconn)
if dbSErr == nil {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
go startServer(port)
<-signals
dbCErr := db.Close()
logger.Debugw("closing db connection & release resources")
if dbCErr != nil {
logger.Error(dbCErr.Error())
}
} else {
logger.Info(dbSErr.Error())
}
}
func startServer(port string) {
logging.GetLogger().Infow("Starting Webservice with", "port", port)
http.ListenAndServe(":"+port, controllers.RegisterRoutes())
}