Professor,
Estou com erro de conexão com o banco postgres.
adriano@mac01062008:~/go/src/adriano$ go run main.go
panic: sql: unknown driver "postgres" (forgotten import?)
goroutine 1 [running]:
main.conectaBanco()
/home/adriano/go/src/adriano/main.go:22 +0x54
main.main()
/home/adriano/go/src/adriano/main.go:28 +0x25
exit status 2
adriano@mac01062008:~/go/src/adriano$ echo $GOPATH
/home/adriano/go
adriano@mac01062008:~/go/src/adriano$ cat go.mod
module github.com/lib/pq
go 1.21.1
main.go
package main
import (
"database/sql"
"html/template"
"net/http"
)
var temp = template.Must(template.ParseGlob("templates/*.html"))
type Produto struct {
Nome string
Descricao string
Preco float64
Quantidade int
}
func conectaBanco() *sql.DB {
conexao := "user=postgres dbname=alura_loja password=adriano hostname=localhost sslmode=disable"
db, err := sql.Open("postgres", conexao)
if err != nil {
panic(err.Error())
}
return db
}
adriano@mac01062008:~/go/src/adriano$ go version
go version go1.21.1 linux/amd64
Quando adiciono a lib no import o erro muda
package main
import (
"database/sql"
"html/template"
"net/http"
_ "github.com/lib/pq"
)
adriano@mac01062008:~/go/src/adriano$ go run main.go
package command-line-arguments
imports github.com/lib/pq
imports github.com/lib/pq: import cycle not allowed
O que fiz de errado?