Reputation: 23
package main
import (
"database/sql"
"fmt"
"html/template"
"net/http"
"unicode"
_ "github.com/lib/pq"
"golang.org/x/crypto/bcrypt"
)
/* const (
host = "localhost"
port = 5432
user = "postgres"
password = "*******"
dbname = "db"
) */
var tpl *template.Template
var db *sql.DB
func main() {
tpl, _ = template.ParseGlob("templates/*.html")
var err error
db, err = sql.Open("postgresql", "root:password@tcp(localhost:localhost/db")
if err != nil {
panic(err.Error())
}
defer db.Close()
http.HandleFunc("/register", registerHandler)
http.HandleFunc("/registerauth", registerAuthHandler)
fmt.Println("Listening")
http.ListenAndServe("localhost:8080", nil)
}
When I run this I get an error:
panic: sql: unknown driver "postgresql" (forgotten import?)
btw, I'm just following a lesson online but they are using MySQL while I on the other hand use Postgres and I'm doing this for my thesis
Upvotes: 2
Views: 3126
Reputation: 312136
You should use the "postgres" database driver string, not "postgresql".
Upvotes: 3