From 900304f9a83b46fce130c992432e42ec2b1250d3 Mon Sep 17 00:00:00 2001 From: Vic Date: Mon, 29 Aug 2022 19:24:52 +0200 Subject: [PATCH] alpha database connection --- app.env | 15 +++++++++++++++ main.go | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 app.env diff --git a/app.env b/app.env new file mode 100644 index 0000000..c798142 --- /dev/null +++ b/app.env @@ -0,0 +1,15 @@ +POSTGRES_HOST=127.0.0.1 +POSTGRES_DB=shelf +POSTGRES_TEST_DB=shelf_test +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_PORT=5432 +ENV=dev + +POSTGRES_DRIVER=postgres +POSTGRES_SOURCE=postgresql://postgres:postgres@localhost:5432/shelf?sslmode=disable + +BCRYPT_PASSWORD=speak-friend-and-enter +SALT_ROUNDS=10 +TOKEN_SECRET=alohomora123! +TOKEN_SECRET_TEST=eyJhbGciOiJIUzI1NiIsInR \ No newline at end of file diff --git a/main.go b/main.go index 88165e6..9543990 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,28 @@ package main import ( - "net/http" - //"database/sql" + "database/sql" + "fmt" + "log" + "net/http" + "github.com/gin-gonic/gin" + "git.sp4ke.xyz/AnisB/shelf_api_go/src/branch/Vic/config/default.go" //_ "github.com/lib/pq" ) func main() { + config, err := config.LoadConfig(".") + if err != nil { + log.Fatalf("Failed to load config: %v", err) + } + + conn, err := sql.Open(config.PostgreDriver, config.PostgreSource) + if err != nil { + log.Fatalf("Failed to connect: %v", err) + } + r := gin.Default() r.GET("/", func(c *gin.Context) {