-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
40 lines (33 loc) · 1.03 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
package main
import (
"database/sql"
"fmt"
"net/http"
"os"
log "github.com/sirupsen/logrus"
webs "github.com/FidelityInternational/possum/web_server"
)
func main() {
if os.Getenv("DEBUG") == "true" {
log.SetLevel(log.DebugLevel)
}
server, err := webs.CreateServer(dbConn, webs.CreateController)
if err != nil {
log.WithFields(log.Fields{"package": "main", "function": "main"}).Fatalf("Error creating server [%s]", err.Error())
}
router := server.Start()
http.Handle("/", router)
port := os.Getenv("PORT")
if port == "" {
log.WithFields(log.Fields{"package": "main", "function": "main"}).Fatal("PORT not set. Exiting.")
}
log.WithFields(log.Fields{"package": "main", "function": "main"}).Infof("Listening on port: %s", port)
err = http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
if err != nil {
log.WithFields(log.Fields{"package": "main", "function": "main"}).Fatal(err)
}
}
func dbConn(driverName string, connectionString string) (*sql.DB, error) {
db, err := sql.Open(driverName, connectionString)
return db, err
}