go

go test in complex folder structure

巧了我就是萌 提交于 2021-01-27 13:32:15
问题 I am building a repository of design patterns in golang. To run all tests, I use this bash script. It works. #!/bin/bash go test creational/abstract_factory/*.go go test creational/builder/*.go go test creational/factory/*.go go test creational/pool/*.go go test creational/prototype/*.go go test creational/singleton/*.go It works fine: prompt> ./runtests.sh ok command-line-arguments 0.006s ok command-line-arguments 0.006s ok command-line-arguments 0.006s ok command-line-arguments 0.006s ok

IntelliJ 2017.1.2 GOLANG debug does not work on breakpoints in packages

十年热恋 提交于 2021-01-27 13:27:07
问题 My application is made up of one main.go file and a handful of packages. When hitting breakpoints within the main.go, IntelliJ works as expected, showing variable values etc., however, when a breakpoint is set in a different package - aside from it being hit, no variables are shown and step over/in features do not work as expected (ignored when hit). Has anyone run into this issue and if so is there a workaround? 来源: https://stackoverflow.com/questions/43851853/intellij-2017-1-2-golang-debug

is concurrent write on stdout threadsafe?

醉酒当歌 提交于 2021-01-27 12:49:57
问题 below code does not throw a data race package main import ( "fmt" "os" "strings" ) func main() { x := strings.Repeat(" ", 1024) go func() { for { fmt.Fprintf(os.Stdout, x+"aa\n") } }() go func() { for { fmt.Fprintf(os.Stdout, x+"bb\n") } }() go func() { for { fmt.Fprintf(os.Stdout, x+"cc\n") } }() go func() { for { fmt.Fprintf(os.Stdout, x+"dd\n") } }() <-make(chan bool) } I tried multiple length of data, with variant https://play.golang.org/p/29Cnwqj5K30 This post says it is not TS. This

golang get massive read tcp ip:port i/o timeout in ubuntu 14.04 LTS

久未见 提交于 2021-01-27 12:42:27
问题 I wrote a golang program which run well in the past several months in ubuntu 12.04 LTS until I upgraded it to 14.04 LTS My program is focused on sending HTTP requests which send about 2-10 HTTP requests per second. The HTTP request address vary. When the problem occurs, first, some of the requests shows read tcp [ip]:[port]: i/o timeout , then after several minutes all requests show read tcp [ip]:[port]: i/o timeout , not any request can be sent. I restart the program, everything become right

Time duration to string 2h instead 2h0m0s

落爺英雄遲暮 提交于 2021-01-27 12:20:44
问题 The default time.Duration String method formats the duration with adding 0s for minutes and 0m0s for hours. Is there function that I can use that will produce 5m instead 5m0s and 2h instead 2h0m0s ... or I have to implement my own? 回答1: Foreword: I released this utility in github.com/icza/gox, see timex.ShortDuration(). Not in the standard library, but it's really easy to create one: func shortDur(d time.Duration) string { s := d.String() if strings.HasSuffix(s, "m0s") { s = s[:len(s)-2] } if

Time duration to string 2h instead 2h0m0s

痴心易碎 提交于 2021-01-27 12:20:22
问题 The default time.Duration String method formats the duration with adding 0s for minutes and 0m0s for hours. Is there function that I can use that will produce 5m instead 5m0s and 2h instead 2h0m0s ... or I have to implement my own? 回答1: Foreword: I released this utility in github.com/icza/gox, see timex.ShortDuration(). Not in the standard library, but it's really easy to create one: func shortDur(d time.Duration) string { s := d.String() if strings.HasSuffix(s, "m0s") { s = s[:len(s)-2] } if

UDP-Client written in Golang fails to receive Message from Server

自作多情 提交于 2021-01-27 10:34:32
问题 I have written a Java Client, which sends a message to the broadcast address. I have also written a Java Server, which accepts all sent messages and sends the message back to the client. Now I wanted to try to do exactly the same in Go, just for gaining some experience. The server works fine and is receiving a message and responding to the Java client. But my Go Client is only sending a message to the Go/Java server but does not receive any message back. According to wireshark the message is

UDP-Client written in Golang fails to receive Message from Server

ε祈祈猫儿з 提交于 2021-01-27 10:34:11
问题 I have written a Java Client, which sends a message to the broadcast address. I have also written a Java Server, which accepts all sent messages and sends the message back to the client. Now I wanted to try to do exactly the same in Go, just for gaining some experience. The server works fine and is receiving a message and responding to the Java client. But my Go Client is only sending a message to the Go/Java server but does not receive any message back. According to wireshark the message is

fatal error all goroutines are asleep deadlock [duplicate]

南楼画角 提交于 2021-01-27 09:33:31
问题 This question already has answers here : throw: all goroutines are asleep - deadlock (2 answers) Closed 5 years ago . Can you explain the following error: fatal error: true true all goroutines are asleep - deadlock! package main import ( "fmt" ) func printer(ch chan bool) { ch <- true } func main() { var c chan bool = make(chan bool, 2) for i := 0; i < 5; i++ { go printer(c) } for i := range c { fmt.Println(i) } } 回答1: Because the channel c is not closed, the range loop does not exit. This

Checking of variable implements interface without compiling

风流意气都作罢 提交于 2021-01-27 09:00:52
问题 I want to know whether a concrete type implements a specefic interface and print it out. I have written an example [0] with a self defined struct (MyPoint) beeing not an interface-type. MyPoint has the function Read as defined in the interface of io.Reader: type MyPoint struct { X, Y int } func (pnt *MyPoint) Read(p []byte) (n int, err error) { return 42, nil } The aim is to get the information that the concrete type p implements the interface io.Writer. Therefore I have written a short main