草庐IT

go-import

全部标签

go - "go test"和 "bazel test"中的不同文件权限错误

如果一个测试想要断言文件权限错误,例如,写入文件系统的根目录,“gotest”返回一个syscall.EACCES错误,而“bazeltest”返回一个系统调用.EPERM。如何让“bazeltest”和“gotest”都通过测试?可以找到一个例子here. 最佳答案 您可以使用bazel--spawn_strategy=standalonetest//...禁用沙箱。我怀疑这会解决这个问题。但是,您可能需要考虑写入/是否是您要测试的行为。如果您需要在不同的操作系统或Docker容器内运行代码,在这种情况下您将获得不同的行为,因此您

go - 如何将嵌套的 JSON 转换为 Go 代码?

这个问题在这里已经有了答案:Initializenestedstructdefinition(3个答案)关闭3年前。我用过:https://mholt.github.io/json-to-go/转换{"id":5533,"action":"/api/v1/private/subscribe","arguments":{"instrument":["BTC-19DEC14"],"event":["order_book","trade","user_order"]}}进入typeAutoGeneratedstruct{IDint`json:"id"`Actionstring`json:"a

go - 使用 exec.Command 运行 sqlite3 .backup

我正在尝试按照此SO答案https://stackoverflow.com/a/25684912/426853给出的方式使用sqlite3.backup命令从Go备份数据库.以下始终在命令行中运行:sqlite3/home/pi/pgclogs/smartlog.db".backup'/home/pi/pgcdata/smartlog.db.bak'"我在Go中将其编码如下:funcDbBackup()(errerror){dbpath:="/home/pi/pgclogs/smartlog.db"bakpath:="/home/pi/pgcdata/smartlog.db.bak"c

mongodb - 如何导入go的mongo-driver bson

我使用gogetgo.mongodb.org/mongo-driver/...安装了mongogo驱动程序,但是每当我尝试使用bson.EC或bson.NewDocument如图所示here,我收到错误:undefined:bson.NewDocument和undefined:bson.EC。我在这里缺少什么?import("go.mongodb.org/mongo-driver/bson")funcmain(){//databaseandcollectionconnection//...filter:=bson.NewDocument(bson.EC.String("_id","fo

go build 找不到修订版

我在计算机A上开发了一个repo并创建了一个我checkin的go.mod/go.sum。我在计算机B上使用go.mod/go.sum文件提取该repo,但是当我尝试构建程序时,无法满足模块约束。$gobuildgo:findinggithub.ibm.com/kms/key-protect-clientv0.1.5go:findinggolang.org/x/toolsv0.0.0-20180221164845-07fd8470d635go:github.ibm.com/kms/key-protect-client@v0.1.5:unknownrevisionv0.1.5go:err

go - 可变 slice 作为参数错误 :cannot initialize 2 variables with 1 value

尝试使用可变参数组合多个slice,我收到错误:无法用1个值初始化2个变量如何调用这个Combine函数?代码如下:funcCombine(ss...[]string)[]string{mp:=map[string]bool{}for_,s:=rangess{for_,v:=ranges{ifv!=""{if_,ok:=mp[v];!ok{mp[v]=true}}}}combined:=[]string{}forv:=rangemp{combined=append(combined,v)}returncombined}tests:=[]struct{caseNamestrings1[]

go - 运行 dep 时出错确保 : Grouped write of manifest, 锁和 vendor :无法统计 VerifyVendor 声称存在的文件

运行depensure时出现以下错误:Groupedwriteofmanifest,lockandvendor:couldnotstatfilethatVerifyVendorclaimedexisted:stat"pathtopackageinsidevendor":nosuchfileordirectory这是我的Gopkg.toml:[[constraint]]name="github.com/PuerkitoBio/goquery"version="1.5.0"[[constraint]]branch="master"name="github.com/auth0-communi

go - 与 goroutine 的混淆

为什么这段代码输出的是Let'sGoGoGo而不是分配给msg的第一个值。我知道这与goroutine有关。如果精通Go的人可以具体地向我解释它,我将不胜感激。这是playground.packagemainimport("fmt""time")//trytorun:gorun-racefuncmain(){msg:="Let'sGo"gofunc(){//Print:"Let'sGo"fmt.Println(msg)}()msg="Let'sGoGoGo"time.Sleep(1*time.Second)} 最佳答案 我能给出的最

go - 如何重置或丢弃缓冲数据

无法重置或丢弃缓冲区。我正在尝试通过串行端口获取数据,我每10秒获取一个固定长度的数据包。我有一个无限循环来连续接收数据包。收到新数据包后,我正在重置缓冲区,但当我收到下一个数据包时,它会覆盖缓冲区,我得到混合数据包。假设我应该每n秒连续接收数据包abcdef。但是当我尝试下面的代码时,我收到数据包bcdefa然后在n秒后cdefab然后defabc等等packagemainimport("bufio""log""time""github.com/tarm/serial")funcmain(){c:=&serial.Config{Name:"/dev/ttyUSB0",Baud:576

go - 在 Go 脚本中运行 'syntax error: A unknown token can’ 时如何修复 `exec.Command` t go here'

我正在尝试在我的Go脚本中使用osascript运行此AppleScript命令,但出现错误0:1:syntaxerror:Aunknowntokencan'tgohere.(-2740)。这是在终端中运行时效果很好的命令!/usr/bin/osascript-e'onrun{f,c}'-e'告诉应用程序“Finder”将(POSIX文件f作为别名)的注释设置为c'-eend"/Users/computerman/Desktop/testfile.png""Hello,World"我下面的Go脚本实际上输出了上面的字符串,我可以直接在终端中剪切和粘贴它并且它可以工作。但是,运行Go脚本