草庐IT

stdin-out

全部标签

go - 在 : panic: runtime error: index out of range 中转换数据结构

我在go中有一个数据结构:typeAPIMainstruct{CodeConvstring`json:"codeConv"`Starttime.Time`json:"start"`Endtime.Time`json:"end"`Details[]struct{IDPrmstring`json:"idPrm"`Keys[]struct{Timestamptime.Time`json:"timestamp"`Valuefloat64`json:"value"`}`json:"keys"`}`json:"details"`}我需要转换为:typeDataGroupedByTSstruct{C

elasticsearch - go + elastigo panic : runtime error: index out of range

我正在用elasticsearch测试golang我正在使用图书馆:https://github.com/mattbaird/elastigo我的问题是当我运行时:gorunelastigo_postal_code2.go编译器显示如下:panic:runtimeerror:indexoutofrangegoroutine1[running]:panic(0x893ce0,0xc82000a150)/opt/go/src/runtime/panic.go:464+0x3ffmain.main()/home/hector/go/elastigo_postal_code2.go:80+0x

json - Golang map : How to strip out empty fields automatically

给定以下结构...packagemodelsimport("time""gopkg.in/mgo.v2/bson""github.com/fatih/structs")typeUserstruct{Idbson.ObjectId`json:"id,omitempty"bson:"_id,omitempty"`Namestring`json:"name,omitempty"bson:"name,omitempty"`BirthDatetime.Time`json:"birth_date,omitempty"bson:"birth_date,omitempty"`}...我通过像这样解析H

go - TCP 将 Stdout 发送到客户端并从客户端读取 Stdin

我正在尝试通过tcp连接远程执行程序我想在客户端服务器之间实时共享标准输出和标准输入。我有以下没有错误处理的测试服务器:p我知道,目前我无法执行带参数的程序,但这很容易处理:)packagemainimport("bufio""bytes""fmt""net""os/exec""strings")funcmain(){l,_:=net.Listen("tcp",":420")deferl.Close()for{//Waitforaconnection.conn,_:=l.Accept()gofunc(cnet.Conn){for{msg,_:=bufio.NewReader(conn)

postgresql - getsockopt : connection timed out

我将我的项目从pythontornado重写为go(使用iris框架)。基本功能测试正常。我在高并发下测试的时候,app总是停一会,然后报错:(dialtcp192.168.1.229:6543:getsockopt:connectiontimedout)6543端口是与pgbouncer一起使用的postgresql端口...pgbouncer和postgresl进程运行正常。另外,我发现memcache连接有时会超时(memcache进程还在工作)。这是否因为连接太多而发生?或者有些连接不是准时关门?我怎样才能避免这个问题? 最佳答案

Go Stdin Stdout 通信

我想执行一个go文件,我将在yaml配置文件中指定它,并以字节为单位向它发送一个Struct。我怎么能这样做?我认为我可以为此使用Stdin和Stdout但是想不通Yaml配置:subscribers:temp:topics:-pi/+/tempaction:./temp/tempBinary这是我的代码:client.Subscribe(NewTopic(a),func(c*Client,msgMessage){cmd:=exec.Command(v.Action)//Iactuallywanttosend[msg]toitsoitcanbeusedtherecmd.Stdin=by

go - 如何使用 Stdin 获取输入并等待 Golang 的 Stdin 中有新数据

我有一段代码需要在每次Stdin中有新输入时执行,但如果Stdin中没有任何内容,程序不应该终止,而是应该等待Stdin中的新数据,然后运行计算代码那个数据。这在Golang中如何实现?下面是一段代码:stat,_:=os.Stdin.Stat()if(stat.Mode()&os.ModeCharDevice)==0{fmt.Println("dataisbeingpipedtostdin")scanner:=bufio.NewScanner(os.Stdin)forscanner.Scan(){text:=scanner.Text()fmt.Println(text)//dosom

unit-testing - 为从中读取的函数填充 os.Stdin

如何在我的测试中填充os.Stdin以获取使用扫描仪从中读取的函数?我使用以下函数通过扫描器请求用户命令行输入:funcuserInput()error{scanner:=bufio.NewScanner(os.Stdin)println("Whatisyourname?")scanner.Scan()username=scanner.Text()/*...*/}现在如何测试这种情况并模拟用户输入?以下示例不起作用。标准输入仍然是空的。funcTestUserInput(t*testing.T){varfile*os.Filefile.Write([]byte("Tom"))os.St

arrays - 我在 golang 中使用 make 方法创建二维数组时遇到问题 "panic: runtime error: index out of range"

Iamnewingolangandtrytolearnwithsmallexamples.所以我正在尝试创建一个二维数组并分配一个值,但我被困在这里任何人都可以帮助我。这是我的代码。packagemainimport("fmt")funcmain(){fmt.Println("Hello,playground")letters:=make([][]string,0,2)letters[0][0]="a"letters[0][1]="b"letters[1][0]="c"letters[1][1]="d"fmt.Println(letters)}运行这段代码时出现错误panic:runt

mongodb - 执行 mgo.Pipe 没有结果,包括 $out

我正在尝试运行一个不返回任何结果的管道,因为最后一个管道运算符是$out。//{$out:"y"}pipeline:=DB.C("x").Pipe(stages).AllowDiskUse()result:=[]bson.M{}err:=pipeline.All(&result)运行管道时出现超时。我假设mgo正在等待结果被读取——永远。 最佳答案 已解决。不要调用All(&result),而是调用Iter()。All会在从一开始就为空的迭代器上调用Next,显然会导致超时。Iter返回一个迭代器,它将被丢弃。没有调用Next,没有