How to install Postgres driver for gorm using gin?

WBOY
Release: 2024-02-09 10:51:08
forward
785 people have browsed it

如何使用 gin 为 gorm 安装 Postgres 驱动程序?

php editor Xiaoxin is here to introduce how to use gin to install the Postgres driver for gorm. Gin is a Go language framework for building high-performance web applications, and Gorm is a popular ORM library in Go language. If you want to connect to the Postgres database when using Gorm, you need to install the corresponding driver first. This article will introduce you in detail how to install the Postgres driver and provide sample code to help you get started quickly. let's start!

Question content

I try to connect a gin application to a postgres database, both are dockerized. I'm getting an error while installing postgres driver. The configuration is described on the website:

$ go get -u gorm.io/driver/postgres
go: downloading gorm.io/gorm v1.24.2
go: downloading github.com/jackc/pgx/v5 v5.3.1
go: downloading github.com/jackc/pgx v3.6.2+incompatible
gorm.io/driver/postgres imports
        github.com/jackc/pgx/v5 imports
        github.com/jackc/pgx/v5/pgtype imports
        net/netip: package net/netip is not in goroot (/usr/local/go/src/net/netip)
Copy after login

There seems to be no net/netip package in goroot. I found that it should be here by default. what happened?

My go version is 1.17.6

$ go version
go version go1.17.6 linux/amd64
Copy after login

Solution

Upgrade to at least version 1.18, this may be the problem

The above is the detailed content of How to install Postgres driver for gorm using gin?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!