[go-nuts] idiomatic code to find, if executable exists in golang

2018-09-25 Thread Nilsocket
package main import ( "os" "os/exec" ) func main() { cmdName := os.Args[1] //either cmd or executable without arguments if _, err := exec.LookPath(cmdName); err != nil { if (err.(*exec.Error)).Err == exec.ErrNotFound { // executable doesn't exist, do some

[go-nuts] Generics a little bit of specialization

2018-09-25 Thread Patrick Smith
One way to allow generic functions to work on both built-in and user-defined types would be to add some specialized functions in the standard library. These would be like overloaded operators, but with function syntax instead of operator syntax. For example, we might have a package operators, conta

Re: [go-nuts] confusion about the implemention of tryStore func in sync.map

2018-09-25 Thread Ian Lance Taylor
On Tue, Sep 25, 2018 at 6:15 PM, wrote: > > I am learning sync.map recently, but the implemention of tryStore func makes > me confused, > why not use the code below instead > > > > func (e *entry) tryStore(i *interface{}) bool { >for { >p = atomic.LoadPointer(&e.p) >if p == ex

Re: [go-nuts] run cmd and capture output on remote machine

2018-09-25 Thread robert engels
You can do this via ssh. > On Sep 25, 2018, at 7:01 PM, Hemant Singh wrote: > > I have been able to run a command on a remote machine using Go. Is there a > working example that shows how to capture the output of the command back to > the client machine? Maybe an interactive shell... > >

[go-nuts] confusion about the implemention of tryStore func in sync.map

2018-09-25 Thread avtimp
I am learning sync.map recently, but the implemention of tryStore func makes me confused, why not use the code below instead func (e *entry) tryStore(i *interface{}) bool { for { p = atomic.LoadPointer(&e.p) if p =

[go-nuts] run cmd and capture output on remote machine

2018-09-25 Thread Hemant Singh
I have been able to run a command on a remote machine using Go. Is there a working example that shows how to capture the output of the command back to the client machine? Maybe an interactive shell... My other choice is to run the command and save its output to a file and copy the file fro

[go-nuts] Re: Updating a struct from goroutines

2018-09-25 Thread Louki Sumirniy
A map[string]interface{} can hold an arbitrary, string labeled collection of any types. You just need to have a type switch and cover all the possible inputs for it. The concurrency is safe as long as only one process is writing to variables at once. If you need multiple concurrent processes to

[go-nuts] "go test" recompiling already-installed packages

2018-09-25 Thread armando . m . ramirez
Hello, I've been playing around with one specific library and trying to speed up my build times. The library is https://github.com/mattn/go-sqlite3 which uses cgo and takes ~45sec to compile. I initially noticed that go build was being slow on packages that imported go-sqlite3, and top reveal

Re: [go-nuts] Updating a struct from goroutines

2018-09-25 Thread Michael Ellis
Thanks, Justin. The struct in the real app is a flat collection of int, string, float64 and bool. I appreciate the reminder, On Tuesday, September 25, 2018 at 4:13:25 PM UTC-4, Justin Israel wrote: > > > > On Wed, Sep 26, 2018, 6:38 AM > wrote: > >> Hi, new gopher here. >> I considered asking t

Re: [go-nuts] Updating a struct from goroutines

2018-09-25 Thread Justin Israel
On Wed, Sep 26, 2018, 6:38 AM wrote: > Hi, new gopher here. > I considered asking this on SO, but they (rightly, IMO) discourage "Is > this a good way to do it?" questions. Hope that's ok here. > > By way of background, I'm porting a largish industrial control application > from Python to Go. T

[go-nuts] Updating a struct from goroutines

2018-09-25 Thread michael . f . ellis
Hi, new gopher here. I considered asking this on SO, but they (rightly, IMO) discourage "Is this a good way to do it?" questions. Hope that's ok here. By way of background, I'm porting a largish industrial control application from Python to Go. The Python version uses multiple processes (abou

Re: [go-nuts] ticker for poisson processes?

2018-09-25 Thread Sebastien Binet
On Tue, Sep 25, 2018 at 11:34 AM David Wahlstedt < david.wahlstedt@gmail.com> wrote: > Hi, > What would be a nice way to implement a ticker that generates events > according to a Poisson process? > The built-in Ticker in ticker.go uses a runtimeTimer that has a field > called period. > I would

[go-nuts] go binary error inside KVM

2018-09-25 Thread aarknt . dev
Good morning, I have an issue that I don't understand with a compiled go binary I am developing. I have compiled the binary correctly in my dev machine. It's working in a lot of other systems (linux i386, x86_64) except in this one [1] (sadly the prod one...) I think the problem is related

[go-nuts] Re: ticker for poisson processes?

2018-09-25 Thread Louki Sumirniy
If you don't mind it involving a small background processing overhead, you could use a goroutine running a hashcash style iterative hash chain generation searching for a specified number of zero bits at one (or both) ends of the resultant hash before you run out of bits. This is extremely rando

[go-nuts] ticker for poisson processes?

2018-09-25 Thread David Wahlstedt
Hi, What would be a nice way to implement a ticker that generates events according to a Poisson process? The built-in Ticker in ticker.go uses a runtimeTimer that has a field called period. I would like to implement a "random ticker" such that each tick interval is random, using ExpFloat64() * d

Re: [go-nuts] a potential problem with go1.11 HTTP library

2018-09-25 Thread Xiangrong Fang
Steven, You are right, I added the domain to my hosts file and the Go client program runs very fast now. The problem is, the domain name in use does exists, and if I ping it, the IP address is resolved instantly! What does this mean in the bug report: DNS queries which are responded to *with

Re: [go-nuts] a potential problem with go1.11 HTTP library

2018-09-25 Thread Steven Hartland
For reference this is the issue tracking the regression I believe your experiencing: https://github.com/golang/go/issues/27525 On 25/09/2018 08:36, Xiangrong Fang wrote: I have a HTTP API and its client written in Go. The client side code is: func upload(link, dir, name string, r io.Reader) {

Re: [go-nuts] a potential problem with go1.11 HTTP library

2018-09-25 Thread Steven Hartland
Sounds like a broken DNS server on the machine, this was something I saw raised before. See the thread "Performance regression of HTTP requests since Go 1.11" for more information.     Regards     Steve On 25/09/2018 08:36, Xiangrong Fang wrote: I have a HTTP API and its client written in Go.

[go-nuts] a potential problem with go1.11 HTTP library

2018-09-25 Thread Xiangrong Fang
I have a HTTP API and its client written in Go. The client side code is: func upload(link, dir, name string, r io.Reader) { var buf bytes.Buffer mw := multipart.NewWriter(&buf) mw.WriteField("dir", dir) mw.WriteField("name", name) ff, _ := mw.CreateFormFile("file", name) io.Copy(ff, r) mw.Close()