記錄一個(gè)go build 構(gòu)建的問題
main.go 文件
package main
import (
"github.com/valyala/fasthttp"
"go.uber.org/zap"
)
var logger *zap.Logger
func init() {
logger, _ = zap.NewProduction()
}
func fastHTTPHandler(ctx *fasthttp.RequestCtx) {
logger.Info("hell, go module", zap.ByteString("uri", ctx.RequestURI()))
}
func main() {
fasthttp.ListenAndServe(":8081", fastHTTPHandler)
}
腳本功能是監(jiān)聽8081端口訪問,打印訪問的頭信息日志
執(zhí)行g(shù)o build 構(gòu)建 報(bào)錯(cuò)
main.go:5:2: //go:build comment without // +build comment
排查了代碼應(yīng)該是沒有問題,必應(yīng)網(wǎng)站查詢問題原因,可能是go 的版本 是低于1.17版本 導(dǎo)致出現(xiàn)的問題,go 引入的依賴庫(kù)包中 1.17版本后 引入了新的構(gòu)建標(biāo)記語(yǔ)法導(dǎo)致的兼容問題
查看當(dāng)前使用的go版本文章來源:http://www.zghlxwxcb.cn/news/detail-559020.html
##的確是低于 1.17 版本
PS D:\coder\gotestprojects\hellomodule> go version
go version go1.16.5 windows/amd64
###安裝go1.17.13 版本
PS D:\coder\gotestprojects\hellomodule> go version
go version go1.17.13 windows/amd64
### 重新執(zhí)行g(shù)o build 命令執(zhí)行成功
查詢解決問題參考鏈接
https://github.com/bitfield/script/issues/131
https://it-explain.com/go-golang-build-error-gobuild-comment-without-build-comment/文章來源地址http://www.zghlxwxcb.cn/news/detail-559020.html
到了這里,關(guān)于解決go build 構(gòu)建問題 go:build comment without // +build comment的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!