Answer the question
In order to leave comments, you need to log in
GoLang, connecting to the database - unexpected EOF what is the reason?
Essence of the question:
On Windows 10, everything works without problems, as soon as I transfer the entire folder to the MacBook and run it. then on startup it gives this "unexpected EOF" error.
What is the reason? The code is the same there and there, respectively, but it does not work on mac os, but everything is ok on Win 10.
package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
const (
host = "localhost"
port = 5432
user = "postgres"
password = "1234"
dbname = "productdb"
)
func main() {
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
host, port, user, password, dbname)
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
defer db.Close()
result, err := db.Exec("insert into Products (model, company, price) values ('iPhone 11 Pro Max', $1, $2)",
"Apple", 82000)
if err != nil{
panic(err) //На это ругается
}
fmt.Println(result.RowsAffected())
}
panic: unexpected EOF
goroutine 1 [running]:
main.main()
/Users/admin/Desktop/test/add.go:37 +0x358
exit status 2
Answer the question
In order to leave comments, you need to log in
As a rule, such a situation indicates problems with connecting to the database, drivers (libraries).
The first thing to do is to set up connections:
db.SetConnMaxIdleTime(0)
db.SetConnMaxLifetime(0)
db.SetMaxIdleConns(10)
db.SetMaxOpenConns(10)
psql -h 127.0.0.1 -p 5432 -U user_name database_name
mysql -h 127.0.0.1 -P 3307 -u user_name -p database_name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question