Home >Backend Development >Golang >How to install Postgres driver for gorm using gin?

How to install Postgres driver for gorm using gin?

WBOY
WBOYforward
2024-02-09 10:51:08819browse

如何使用 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)

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

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!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete