我正在嘗試使用pgx打開與postgres數(shù)據(jù)庫的連接,并且我收到以下錯誤:./dbservice.go:12:26: too many arguments in call to "github.com/jackc/pgx".Connect have (context.Context, string) want ("github.com/jackc/pgx".ConnConfig)./dbservice.go:13:18: too many arguments in call to conn.Close have (context.Context) want ()./dbservice.go:21:44: cannot use context.Background() (type context.Context) as type string in argument to conn.Query我不確定錯誤要求我在這里做什么。 當(dāng)我從主文件調(diào)用它時可以工作,但在這里它不起作用。代碼如下:pgx.Connectfunc initNodes(nodes *[]Node, searchNodes *[]SearchNode, storageNodes *[]StorageNode) error { conn, err := pgx.Connect(context.Background(), DATABATE_URL) defer conn.Close(context.Background()) if err != nil { fmt.Printf("Connection failed: %v\n", err) os.Exit(-1) }...func main() { a:= Arbiter{} a.init()}有什么想法嗎?
- 1 回答
- 0 關(guān)注
- 378 瀏覽
添加回答
舉報
0/150
提交
取消
