First attempt at splitting the Go code into seperate files to clean things up.

This commit is contained in:
2021-09-08 22:51:00 -05:00
parent bb01c11859
commit 20a6365159
3 changed files with 66 additions and 62 deletions
+21
View File
@@ -0,0 +1,21 @@
package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
func getSQLConnection() *sql.DB {
//Note: The postgres driver seems to get confused when no password is supplied, so omit it in the connection sting.
//https://rajyavardhan.medium.com/when-you-get-relation-does-not-exist-in-postgres-7ffb0c3c674b
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=disable", "localhost", 5432, "postgres", "inventory")
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
return db
}