MacOS 安装 go-sqlite3 问题与解决

简介: MacOS 安装 go-sqlite3 问题与解决

如果直接下载的话,报错如下:


go get github.com/mattn/go-sqlite3
go get: module github.com/mattn/go-sqlite3: reading https://athens.azurefd.net/github.com/mattn/go-sqlite3/@v/list: 504 Gateway Timeout

第一步


Mac OS X
1. 经过 Homebrewn 安装:html
brew install pkgconfig
brew install sqlite3

执行结果如下:


➜  ~ brew install pkgconfig
Warning: pkg-config 0.29.2_3 is already installed and up-to-date.
To reinstall 0.29.2_3, run:
  brew reinstall pkg-config
➜  ~ brew install sqlite3
Warning: sqlite 3.37.0 is already installed and up-to-date.
To reinstall 3.37.0, run:
  brew reinstall sqlite

第二步


brew link pkgconfig --force
brew link sqlite3 --force

第三步


go get github.com/mattn/go-sqlite3

结果如下:

go: downloading github.com/mattn/go-sqlite3 v1.14.9

sqllite 测试用例


package mysql
import (
 "fmt"
 "testing"
 "github.com/jinzhu/gorm"
 //_ "github.com/jinzhu/gorm/dialects/sqlite"
 _ "github.com/mattn/go-sqlite3"
)
type Product struct {
 gorm.Model
 Code  string
 Price uint
}
func (Product) TableName() string {
 return "hax_products"
}
func Test(t *testing.T) {
 db, err := gorm.Open("sqlite3", "test.db")
 if err != nil {
  panic("failed to connect database")
 }
 defer db.Close()
 gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
  return "hax_" + defaultTableName
 }
 db.LogMode(true)
 // Migrate the schema
 db.AutoMigrate(&Product{})
 db.Create(&Product{Code: "L1212", Price: 1000})
 var product Product
 db.First(&product, 1)
 var products []Product
 db.Find(&products)
 fmt.Printf("Total count %d", len(products))
}

macos 安装有问题,可以参考 https://segmentfault.com/q/1010000000162180 这个解决

相关文章
|
7月前
|
关系型数据库 Java MySQL
【Sqlite】sqlite安装与与使用图文详解
【Sqlite】sqlite安装与与使用图文详解
121 0
|
10月前
|
NoSQL 数据可视化 Ubuntu
一文便知 GO 中mongodb 的安装与使用
咱们来回顾一下上次分享的内容: • 如何使用log 包 • log 包原理和具体实现 • 自定义日志
289 0
|
22小时前
|
Linux Go iOS开发
【Go语言专栏】Go语言入门教程:从安装到第一个Hello World
【4月更文挑战第30天】本文介绍了Go语言的基础知识,包括其由Google开发、静态类型、编译型特点以及在服务器端编程等领域的应用。文章详细阐述了如何安装Go语言,包括在Windows、macOS和Linux上的步骤,并提供了验证安装的方法。接着,介绍了设置工作空间和配置环境变量的过程。最后,通过创建并运行一个"Hello, World!"程序,让读者初步体验Go语言的编程。文章还提供了进一步学习Go语言的资源,助力读者深入学习。
|
21天前
|
Go API iOS开发
go语言下载安装
go语言下载安装
|
3月前
|
Go C语言
安装go-sqlite3包时报exec: "gcc": executable file not found in %PATH%解决办法
安装go-sqlite3包时报exec: "gcc": executable file not found in %PATH%解决办法
|
3月前
|
Unix Linux Go
开心档之 Go 语言环境安装
开心档之 Go 语言环境安装
|
4月前
|
Go
go语言安装及其环境配置
go语言安装及其环境配置
38 0
|
4月前
|
Linux Go
Centos 7安装Go语言环境
Centos 7安装Go语言环境
26 0
|
9月前
|
Unix Linux Go
Go 语言开发环境一键安装 | Linux版
Go 语言开发环境一键安装 | Linux版
127 0
|
10月前
|
NoSQL Ubuntu Linux