From c291f597088f8074aa7174786bec71ca55542469 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 24 Nov 2024 22:05:22 -0600 Subject: [PATCH] PQ test --- go.mod | 2 ++ main.go | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a00735c..528ea91 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/gopatchy/shortlinks go 1.22 + +require github.com/lib/pq v1.10.9 diff --git a/main.go b/main.go index 15c2ca1..b490acd 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,29 @@ package main import ( + "database/sql" "fmt" "log" "net/http" "os" + + _ "github.com/lib/pq" ) func main() { port := os.Getenv("PORT") if port == "" { - port = "80" + log.Fatalf("please set PORT") + } + + pgConn := os.Getenv("PGCONN") + if pgConn == "" { + log.Fatalf("please set PGCONN") + } + + _, err := sql.Open("postgres", pgConn) + if err != nil { + log.Fatal(err) } bind := fmt.Sprintf(":%s", port)