草庐IT

go-mocket

全部标签

go - 如果 golang 文件依赖于 Asset 函数,如何构建它

我有以下Golang文件:**main.go**funcindexPage(whttp.ResponseWriter,r*http.Request){var(data[]byteerrerror)ifExtAssetDir==""{data,err=Asset("index.html")}else{varf*os.Filef,err=os.Open(ExtAssetDir+"/index.html")data,err=ioutil.ReadAll(f)}它依赖于Assets包/功能。在构建main.go时如何包含该(Assets)依赖项。当我构建ma​​in.go时出现以下错误.\ma

go - 构建时在 golang 中找不到包 "github.com/user../../"

我正在尝试从github源代码构建一个项目。我发现一些源代码导入了如下所示的包:import("os""github.com/bivas/rivi/commands""github.com/mitchellh/cli")但是在构建项目时每次都会报错:user-MacBook-Pro:riviuser$gobuildrivi.gorivi.go:6:2:cannotfindpackage"github.com/bivas/rivi/commands"inanyof:/usr/local/Cellar/go/1.7.5/libexec/src/github.com/bivas/rivi/c

docker - 在 docker 构建期间不能 `go get` 依赖项

我对Docker和Go都很陌生,所以这可能是显而易见的,但我的谷歌搜索没有找到任何东西。我正在尝试使用docker构建一个简单的go程序,但我在依赖项方面遇到了麻烦。转到文件:packagemainimport("fmt""log""html""net/http""github.com/gorilla/mux")funchello(writerhttp.ResponseWriter,r*http.Request){path:=mux.Vars(r)["rest"]fmt.Fprintf(writer,"Hello,%q",html.EscapeString(path))}funcmai

go - 在 VM 中运行 go-bindata 会导致输入/输出错误?

我在我的虚拟机中运行go-bindata。好像是提示输入/输出错误,没有任何进一步的描述。然而,当我在我的主机操作系统上运行相同的go-bindata时,绝对没有错误。我在这里缺少什么?步骤:1)UseanoraclevirtualboxVM.Enablenetworkingandstartthevm.Downloadthego-bindataandcheckifitisinstalled.Youcandosobycheckingthehelpmenu(go-bindata-h)ortheversion(go-bindata-version).Igetaproperhelpmenuan

go - Golang中的模板文件夹解析错误

我尝试使用golang和ginframework运行Web应用程序时遇到错误,它无法解析保存在名为'templates'的文件夹中的模板。我在下面粘贴了终端并突出显示了块中的错误。请参见tjat[GIN-debug][WARNING]创建一个已经附加了Logger和Recovery中间件的Engine实例。[GIN-debug][WARNING]Runningin"debug"mode.Switchto"release"modeinproduction.-使用环境:exportGIN_MODE=release-使用代码:gin.SetMode(gin.ReleaseMode)****p

go - 不能用方法迭代结构?

我的问题是,我有指定的应用程序:myapp|-app/main.go|-data/a.go|-data/b.go在a.go中我有带方法的结构packagedatatypeAstruct{Field_astringField_bstring}func(aA)SomeMethod()string{return"somemethodA"}在b.go中类似:packagedatatypeBstruct{Field_astringField_bstring}func(bB)SomeMethod()string{return"somemethodB"}现在我在main.go中以这种方式引用:pac

go - 等于 golang 文档中的关键字歧义

在这种情况下,我无法理解Equals关键字。有人可以解释它是类型还是函数,因为我找不到与此相关的golang文档。https://github.com/ory/ladon/blob/9fada03c11c183e37c13f581ee6deca8d8e747f9/condition_string_equal.go#L19-L21 最佳答案 struct是golang中的用户定义类型,具有一组字段。所以在你的情况下typeStringEqualConditionstruct{Equalsstring`json:"equals"`}St

go - 在 Go 程序中返回的参数太多

我制作了这个简单的软件来连接到AWS并生成一个预签名的puturl:packagemainimport("fmt""log""time""github.com/minio/minio-go""github.com/kelseyhightower/envconfig")//AWScontainstheconfigurationtoconnectandcreateapresignedurlonAWS.typeAWSstruct{EndpointstringAccessKeyIdstringSecretAccessKeystringSSLboolBucketHoststringBucketK

go - 如何计算死掉的例程?

我有一段代码,我们运行多个go例程来接收值。我试图统计有多少goroutines由于某些异常或错误而死亡。我不想更新正常执行的计数。for{gofunc(){err:=receiveValues()}()}这里,receiveValues会调用其他函数,如果失败则返回errfuncrecieveValues()error{iferr,val:=callSomeFunc();err!=nil{returnerr}iferr2,val2:=callOtherFunc(val);err2!=nil{returnerr2}}我可以检查receiveValues()何时返回错误并增加我的计数,但

go - 安装 Golang 时遇到的问题

我在安装golang时遇到了一些问题,已使用以下方法安装它。sudo更新$sudocurl-Ohttps://storage.googleapis.com/golang/go1.10.1.linux-amd64.tar.gz$sudotar-xvfgo1.10.1.linux-amd64.tar.gz$sudomvgo/usr/local一切顺利,直到上述步骤。但是当我发出以下命令时,我收到一条消息$echo'exportPATH=$PATH:/usr/local/go/bin'>>~/.profile消息:bash:export:'/usr/local/go/bin':notaval