草庐IT

FILE_IN_PROCESS

全部标签

unit-testing - 如何使用 os.O_RDWR 和 os.O_CREATE 标志测试 file.Open?

我正在尝试为结构构造函数编写单元测试,如果在file.Open期间发生错误,它也可能返回nil。我不知道如何使用标志测试/模拟文件错误:os.O_RDWR|os.O_CREATE|os.O_APPEND我试图在测试中检查nil值,但失败了。构造函数:typeAppstruct{someFieldstringlog*log.Logger}funcNew()*App{app:=&App{}f,err:=os.OpenFile("info.log",os.O_RDWR|os.O_CREATE|os.O_APPEND,0666)iferr!=nil{fmt.Printf("erroropeni

go - x/手机 : Launch a android application with given package name [String] in go

下面是用go写的函数:funcLaunchApplication(packageNamestring){Query:howcanIexecuteapplicationwithgivenpackageName}使用gomobile生成java绑定(bind)[.aar]。我想包含在我的android应用程序中生成的.aar,并从java层调用LaunchApplication("com.package.name")到本地go层,go层应该运行该应用程序。在java应用中,使用包名运行apk的方法如下:Processprocess=Runtime.getRuntime().exec("am

gob 编码到/从 *os.File 解码不工作

当我使用文件指针时f*os.File我得到一个空映射funcdecode(f*os.File,bmap[string]interface{})error{err:=gob.NewDecoder(f).Decode(&b)fmt.Printf("%+v\n",b)returnerr}funcencode(f*os.File,bmap[string]interface{})error{bb:=map[string]interface{}{"X":1,"Greeting":"hello",}err:=gob.NewEncoder(f).Encode(bb)f.Sync()//fmt.Prin

go - [CodeEval][GO] CodeEval 错误 : Process was aborted due to timeout

我正在尝试提交我的https://www.codeeval.com/open_challenges/158/解决方案这是一个冒泡排序。我用GOlang编写代码,在我的PC上它运行良好且快速!我尝试使用go的输入代码示例,我也尝试了自己的一段代码。谁能帮帮我?我尝试以某种方式更改代码,但没有任何效果。提前致谢。 最佳答案 您的代码中可能缺少某些极端情况。参见https://getsatisfaction.com/codeeval/topics/bubble-sort-iterations-are-too-high-causing-so

去教程: what is the & doing in this line?

我正在做go教程,我对这个练习有疑问...https://tour.golang.org/moretypes/5我之前只在基本的C代码中简单地使用过指针和地址。我的理解是p=&Vertex{1,2}//hastype*Vertex行指向一个新变量p地址Vertex.这不是重新定义了struct的定义吗?设置X,Yint=1,2这里是教程的完整代码:packagemainimport"fmt"typeVertexstruct{X,Yint}var(v1=Vertex{1,2}//hastypeVertexv2=Vertex{X:1}//Y:0isimplicitv3=Vertex{}//

file - os.File 是如何实现 io.Writer 的?

我能做到:f,err:=os.Create("file")iferr!=nil{....}by:=bufio.NewWriter(f)还有这个:var_io.Writer=&os.File{}os.File的包文档导致thissourcefile它确实包含一个未导出的写函数,但是当我尝试使用未导出的函数实现接口(interface)时出现错误。var_Disease=&Scratch{}//*Scratchdoesn'timplementDiseasehavespread()wantSpread()typeDiseaseinterface{Spread()}typeScratchstr

amazon-web-services - 如何克服 ResourceNotFoundException : Requested resource not found error in Go lang?

我是Golang的初学者,我正在尝试使用AWS在Golang和Dynamodb之间建立连接,并使用Golang编写的API在dynamodb中插入数据。任何帮助,将不胜感激。下面是我正在尝试做的代码:packagemainimport"fmt" import("github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session""github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/service/dynamodb""github

xml - 戈朗 : Undefined field in struct error

我正在尝试使用golang解析xml文件。我已经创建了所需的结构,但是当我尝试编译go文件时,出现以下错误:./main_v4.go:146:aggInfoXml.IpAddr.Hports未定义(类型[]Addr没有字段或方法Hports)我被这个问题难住了。这是我的代码:packagemainimport("net/http""html/template""os/exec""io/ioutil""os""encoding/xml""encoding/json""fmt""bufio""github.com/gorilla/websocket""time""log")typePerc

linux - 戈朗 : ssh running remote scripts: No such file or directory

我正在使用ssh模块在远程机器上运行shell脚本://ssh-run.gopackagemainimport("bytes""flag""fmt""log""time""golang.org/x/crypto/ssh")var(flagUser=flag.String("user","","")flagPwd=flag.String("pwd","","")flagHost=flag.String("host","","")flagCmd=flag.String("cmd","",""))funcmain(){flag.Parse()log.SetFlags(log.Lshortfi

file - Go connection.Writer 和 reader 行为不正常,在一次读取操作中读取 2 写入

我正在尝试从客户端读取文件,然后将其发送到服务器。它是这样的,你输入send在客户端程序中,然后是将被发送到服务器。服务器通过TCP连接从客户端读取2个东西,首先是命令send其次是文件的内容。但是,有时我的程序会随机包含中的文件内容。字符串。例如,假设我有一个名为xyz.txt的文本文件,其内容是“Hellowworld”。服务器有时会收到sendxyz.txtHellowworld.有时它不会,但它工作得很好。我认为这是同步或不刷新读写器缓冲区的问题。但我不太确定。提前致谢!客户端代码:funcsendFileToServer(fileNamestring,connectionne