-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (31 loc) · 972 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
package main
import (
"context"
"fmt"
"net/http"
"os"
"github.com/FactoryCICD/factory-api/cmd/server"
"github.com/FactoryCICD/factory-api/internal/config"
dbcontext "github.com/FactoryCICD/factory-api/pkg/db"
"github.com/FactoryCICD/factory-api/pkg/log"
"github.com/jackc/pgx/v5"
)
func main() {
// Create logger
logger := log.New().With(context.Background(), "version", "1.0.0")
// Create connection to db
conn, err := pgx.Connect(context.Background(), config.EnvVars.GetDBURI())
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
// Close the connection
defer conn.Close(context.Background())
logger.Info("Connection to database established")
// Create a new dbcontext
db := dbcontext.New(conn)
// Start the server
app := server.Build(logger, db)
logger.Info("Server is running on port ", config.EnvVars.GetPort())
http.ListenAndServe(fmt.Sprintf(":%s", config.EnvVars.GetPort()), app)
}