dinheiro

commit 7a748a6a6093a5622349e89a92713e897ec57bcf

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

cmd/server: rig up the db middleware

 cmd/server.go | 18 +++++++++++++++++-


diff --git a/cmd/server.go b/cmd/server.go
index 851c9bb371249911957bc140cd7b56477117f818..82e95bff497f0a492f0959bcc470a48ab263df5f 100644
--- a/cmd/server.go
+++ b/cmd/server.go
@@ -6,14 +6,19 @@ 	"log"
 	"path/filepath"
 	"strings"
 	"net/http"
+	"database/sql"
+	"encoding/json"
 
 	"github.com/go-chi/chi/v5"
 	"github.com/go-chi/chi/v5/middleware"
+	_ "github.com/lib/pq"
 	goRedis "github.com/go-redis/redis/v8"
 
 	"git.eletrotupi.com/git/dinheiro/config"
+	"git.eletrotupi.com/git/dinheiro/db"
+	"git.eletrotupi.com/git/dinheiro/keys"
 	"git.eletrotupi.com/git/dinheiro/redis"
-	"git.eletrotupi.com/git/dinheiro/keys"
+	"git.eletrotupi.com/git/dinheiro/types"
 )
 
 func FileServer(router chi.Router, path string, root http.FileSystem) {
@@ -78,8 +83,19 @@ 	if err != nil {
 		log.Fatal("Invalid redis host")
 	}
 
+	dbConnString, ok := appConfig.Get("database", "connection-string")
+	if !ok {
+		log.Fatalf("Invalid database::connection-string config")
+	}
+
+	dbConn, err := sql.Open("postgres", dbConnString)
+	if err != nil {
+		log.Fatalf("Failed to open a connection to the database: %v", err)
+	}
+
 	rc := goRedis.NewClient(ropts)
 	router.Use(config.Middleware(appConfig))
+	router.Use(db.Middleware(dbConn))
 	router.Use(redis.Middleware(rc))
 	router.Use(middleware.RealIP)
 	router.Use(middleware.Logger)