草庐IT

TRAVIS_OS_NAME

全部标签

string - 如何保存呈现的模板而不是打印到 os.Stdout?

我是Go的新手。我一直在搜索文档。在下面的Playground代码中,它正在屏幕上渲染和打印它。我希望将呈现的文本存储在字符串中,以便我可以从函数中返回它。packagemainimport("os""text/template")typePersonstruct{Namestring//exportedfieldsinceitbeginswithacapitalletter}funcmain(){t:=template.New("sammple")//createanewtemplatewithsomenamet,_=t.Parse("hello{{.Name}}!")//parse

go - {{template "name"pipeline}} 是什么意思

这个问题在这里已经有了答案:Golangtemplateenginepipelines(1个回答)关闭4年前。在https://golang.org/pkg/text/template/#hdr-Actions,有如下解释{{template"name"pipeline}}Thetemplatewiththespecifiednameisexecutedwithdotsettothevalueofthepipeline.这是什么意思?什么是点?例如,我看到下面的模板代码——{{define"header"}}{{template"top".}}{{template"needs"}}..

go - 使用 os/exec 命令从 Windows 交叉编译到 Linux

标题基本上就是这么说的。我知道我能做到setGOOS=linuxsetGOARCH=amd64在gobuild之前在cmd中,但我正在尝试编写一个构建脚本并使用exec.Command完成所有操作。我的gobuild-oetc与exec.Command(它构建)一起工作,但是在执行以下任一命令后在测试脚本中打印GOOS时:cmd:=exec.Command("set","GOOS=linux")//ORcmd:=exec.Command("setGOOS=linux")我得到了windows。有什么想法吗?谢谢! 最佳答案 我强烈建

go - 如果通过 os.exec 运行,调用的程序失败

我不确定这是调用程序的问题还是我调用程序的方式导致的问题。因此,我从源代码开始。我需要从程序中调用ssh(如果您对原因感兴趣,我将在下面提及)但ssh会静默退出。当我从shell调用ssh-vuser@remotehost时,这成功了:在stderr上显示了想要的调试输出我被要求输入密码我可以看到远程主机shell但是当我在我的程序中执行相同操作时(myssh-vuser@remotehost只会发生这种情况:我被要求输入密码既没有显示stderr上的调试输出,也没有到达远程主机shell。这是我的源代码:packagemainimport("fmt""log""os""os/exec

go - Route53 : query domain records by Domain Name

使用Go和AWS-SDK我正在尝试查询AWS控制台中Route53->HostedZones下列出的route53CNAME和A记录。我可以使用以下代码进行查询,但它需要我必须提前知道的(神秘的)HostedZoneId。是否有不同的功能,或基于域名(例如XXX.XXX.com)的HostedZoneId查找?AWSLogin(instance)svc:=route53.New(instance.AWSSession)listParams:=&route53.ListResourceRecordSetsInput{HostedZoneId:aws.String("Z2798GPJN9C

go - 使用模块时如何让 Travis 更快地构建

我们在一个项目中使用了gomodules和travis。每次Travis构建项目时,gomodules都会获取所有依赖项,这会增加构建时间。有什么方法可以减少该时间或避免每次都获取部门? 最佳答案 是的,您可以缓存Go模块以加快构建过程。-language:goscript:-yourscriptcache:directories:-$HOME/.cache/go-build#Cachethebinaries-$HOME/gopath/pkg/mod#CachetheGomodules引用:https://restic.net/bl

string - golang 将 os.ModePerm 转换为字符串

我想将文件的权限表示形式作为string。这是我想要做的:fileInfo,err:=os.Lstat(path)fileMode:=fileInfo.Mode()//fileMode.String()givesdturwxrwxrwxor-rwxrwxrwx//whichidonotwantbecausethesizeisnotalwaysthesameunixPerms:=fileMode&os.ModePerm对于这两种情况,我都得到了-rwxrwxrwx,这与我正在寻找的很接近。但是,返回的对象是os.FileMode类型。我怎样才能将它转换成string?

go - 如何将 os/exec 输出传递给 gin get

我想将操作系统命令的退出代码传递给URL。我正在使用Gin,但我对任何方式都持开放态度。我只想将错误传递给HTTP响应。到目前为止,我找不到将os输出放入HTTP响应示例的示例,所以我来到这里希望有人知道。packagemainimport("fmt""github.com/gin-gonic/gin""os/exec")funcHomepage(c*gin.Context){c.JSON(200,gin.H{"message":"HelloWorld"}}funcPowershell(c*gin.Context){//RunthispowershellprogramfromGo.cm

go - 我如何使用 Go 的 os/exec 库将错误消息输入到我的 Go 程序中?

我正在运行执行“psql”的代码。它应该返回一些错误代码,因为数据库未启动。它应该返回psql:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/tmp/.s.PGSQL.5432"?但是它返回标准错误2013/11/2115:06:19exitstatus2exitstatus1这是代码packagemainimport("fmt""log""os/exec")funcmain(){out,err:=exec.

bash - os.exec.Command 和 pbcopy

我正在尝试执行bash命令"helloworld"|/usr/bin/pbcopy里面Go:packagemainimport("fmt""os/exec""strings")funcCmd(cmdstring){fmt.Println("commandis",cmd)parts:=strings.Fields(cmd)head:=parts[0]parts=parts[1:len(parts)]out,err:=exec.Command(head,parts...).Output()iferr!=nil{fmt.Printf("%s",err)}fmt.Println("out")f