2
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

1 Answer 1

3

You should use the "postgres" database driver string, not "postgresql".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.