First attempt at splitting the Go code into seperate files to clean things up.
This commit is contained in:
+21
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user