解決go打包時報錯 models/util/code.go:23:2: cannot find package "github.com/boombuler/barcode" in any of:


問題點
缺少github.com/boombuler/barcode程序

models/util/code.go:23:2: cannot find package "github.com/boombuler/barcode" in any of: /root/gopath/src/gybadminapi/vendor/github.com/boombuler/barcode (vendor tree) /root/go/src/github.com/boombuler/barcode (from $GOROOT) /root/gopath/src/github.com/boombuler/barcode (from $GOPATH) models/util/code.go:24:2: cannot find package "github.com/boombuler/barcode/qr" in any of: /root/gopath/src/gybadminapi/vendor/github.com/boombuler/barcode/qr (vendor tree) /root/go/src/github.com/boombuler/barcode/qr (from $GOROOT) /root/gopath/src/github.com/boombuler/barcode/qr (from $GOPATH) models/util/code.go:25:2: cannot find package "github.com/golang/freetype" in any of: /root/gopath/src/gybadminapi/vendor/github.com/golang/freetype (vendor tree) /root/go/src/github.com/golang/freetype (from $GOROOT) /root/gopath/src/github.com/golang/freetype (from $GOPATH)

解決辦法 :

在使用go的時候如果依賴導入github上的,比如下面樣式

import "github.com/boombuler/barcode"

在/root/gopath/目錄下執行下載,執行get操作

go get github.com/boombuler/barcode

它會下載到你的gopath目錄下

在我們引入第三方的時候,其會在三個地方區查找
1、GOROOT路徑
2、GOPATH路徑
3、在原目錄中的vendor目錄下進行查找

get執行后,發現src目錄下產生相應的目錄,那么報錯解決

 

下面安裝go過程可忽略~~~~~~~~~

=============================================================

一、安裝go環境

1.下載go軟件包

官網:https://goproxy.io/zh/

wget https://gomirrors.org/dl/go/go1.15.2.linux-amd64.tar.gz

2.解壓:

tar xf go1.15.2.linux-amd64.tar.gz

3.創建目錄

go安裝目錄:/root/go(無需創建,解壓自得)

go運行目錄:mkdir -p /root/gopath 

4.添加環境變量

vim /etc/profile

末尾添加:

export GOROOT=/root/go
export GOPATH=/root/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOPROXY=https://goproxy.io

最后一行表示,如果在構建中缺少構建文件,將會自動下載

5.立即生效

source /etc/profile

6.查看版本

go version

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM