[go-nuts] Json performance curiosity

2017-10-10 Thread snmed
Hi all I wondering why https://github.com/json-iterator/go is so much faster then https://github.com/pquerna/ffjson and https://github.com/mailru/easyjson. As far as i know ffjson and easyjson using static code generation, but json-iterator on the other hand doesn't use code generation. Has an

[go-nuts] Re: How to convert JSON message to Go struct

2017-10-10 Thread Dave Cheney
Sadly this is not a JSON object, it's an array containing an array containing four values. The Go defintion created for you by that tool is the best way to express this data in Go. On Wednesday, 11 October 2017 17:40:41 UTC+11, Christian LeMoussel wrote: > > > Hi, I'm new to Go, > > I have diff

[go-nuts] How to convert JSON message to Go struct

2017-10-10 Thread Christian LeMoussel
Hi, I'm new to Go, I have difficulty to converts JSON into a Go type definition. *JSON* [["19c87d4ddf59160406821ca102aa4f49846ecf5ac3d41d2007883834", 75, "b54317cb538c6b3a5ae8b84f8b53c83652037038ad8ad6bef4c8b43a", 101]] *Go type definition with JSON-to-Go Convert

[go-nuts] go on Windows 10 from the bash shell (and the cmd shell)

2017-10-10 Thread Pat Farrell
I've installed the go 1.9 binary distribution on my windows 10 laptop. I just let the install do the defaults. (in addition to learning go, I'm trying to see if I can live with bash under Windows, or if I have to reboot to a linux distro to avoid going crazy, that is a separate topic) in the c

[go-nuts] [ANN] Frame - Plan9 libframe in Go

2017-10-10 Thread as
For those of you who miss the Plan9 editable text boxes, here's a Go package that approximates them: https://github.com/as/frame It's not a c2go conversion, but the functionality is almost identical at the API level. A few extra things added - Raw ASCII bytes - Elastic tabstops - Semantic Rep

[go-nuts] Re: A few go 2 suggestions

2017-10-10 Thread rsr via golang-nuts
Toy syntax to address fork-join patterns: go somefunc() (foo int64 /* must match return of somefunc()) { // this block executed when the goroutine for somefunc() terminates; return values of somefunc are values of signature // as a defer-equivalent so that the defer() for panic recovery

Re: [go-nuts] defer go [was: A few go 2 suggestions]

2017-10-10 Thread Michael Jones
(part 2) ...sorry, I should have said: "f() will complete its evaluation before g() is runnable, it g() runs at all." "g() will become runnable before evaluation of f() is started" "f() will evaluate completely and then g() will evaluate completely before func() returns" On Tue, Oct 10, 2017 a

Re: [go-nuts] defer go [was: A few go 2 suggestions]

2017-10-10 Thread Michael Jones
First... go func() { f() go g() }() is tremendously different than: go func() { go g() f() }() and neither is equivalent to : go func() { f() g() } () ...and on the order of evaluation and visibility and weak memory coher

[go-nuts] defer go [was: A few go 2 suggestions]

2017-10-10 Thread Juliusz Chroboczek
> 1. "defer go" extend defers to work on goroutine exit with mechanism just > like defer, but if we say "defer go f()" > instead of "defer f()" then we run on goroutine exit. Very big gains for > scaling here IMHO. If I read the language specification right, goroutines have no identity: a gor

Re: [go-nuts] A few go 2 suggestions

2017-10-10 Thread Dan Kortschak
On Tue, 2017-10-10 at 06:13 -0700, Scott Cotton wrote: > 1. "defer go"   extend defers to work on goroutine exit with > mechanism just  > like defer, but if we say "defer go f()" > instead of "defer f()" then we run on goroutine exit.  Very big gains > for  > scaling here IMHO. How is this differ

Re: [go-nuts] Re: big.Int.SetString fails with string created with bytes.Buffer

2017-10-10 Thread Rob Pike
That's not necessary. As it says in the last part of the quoted documentation, In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer. Using NewBuffer to create an empty buffer is a mistake. -rob On Wed, Oct 11, 2017 at 2:47 AM, Marvin Ste

Re: [go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Christian LeMoussel
connections.send(s, "getwork", 10) I searched a little bit more and here is in Python send() function def send(sdef, data, slen): sdef.setblocking(0) sdef.sendall(str(len(str(json.dumps(data.encode("utf-8" ).zfill(slen)) sdef.sendall(str(json.dumps(data)).encode("utf-8"))

[go-nuts] Speeding up a concurrent "simple" web server

2017-10-10 Thread Dave Cheney
Looking at the ab output I think shell escaping has busted the query you pass to your request. Nit: an is widely considered by gophers to be unreliable, you might want to try other tools like wrk, hey (née boom), or siege. -- You received this message because you are subscribed to the Google

Re: [go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Gianguido Sorà
Since the server is communicating using JSON structures, you should unmarshal the Read() data in a struct to actually use it: https://blog.golang.org/json-and-go. Unlike Python where JSON is typically handled through dictionaries, in Go you either provide a structure to unmarshal data to, or work

Re: [go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Bruno Albuquerque
Yes, the server is not an http/rpc server so using DialHTTP() does not make much sense. Try with net.DialTCP() and use Write() and Read() on the returned TCPConn to send requests and get the responses. On Tue, Oct 10, 2017 at 11:48 AM Christian LeMoussel wrote: > I'm having trouble translating

Re: [go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Shawn Milochik
I think the problem is that the Python code is using a standard socket, and the Go code is using the rpc package. Try using net.Dial instead of rpc.DialHTTP. A socket is just a socket. An rpc connection probably tries to do a bit more upon connection but isn't getting what it expects from the vani

[go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Christian LeMoussel
I'm having trouble translating Python code into GO. s = socks.socksocket() s.connect((mining_ip_conf, int(port))) # connect to pool connections.send(s, "getwork", 10) work_pack = connections.receive(s, 10) db_block_hash = (work_pack[-1][0]) diff = int((work_pack[-1][1])) paddress = (work_pac

Re: [go-nuts] Scope of variables with closures

2017-10-10 Thread etienne . daspe
Thank you for the answer :) Etienne On Tuesday, 10 October 2017 16:58:43 UTC+2, Ian Lance Taylor wrote: > > On Tue, Oct 10, 2017 at 7:22 AM, > > wrote: > > > > I'm trying to understand the scope of variables when using closures. > > I wrote a simple program to compute fibonacci sequence with

Re: [go-nuts] In `WaitGroup`, why should `Add(positive delta)` called before `Wait` if counter is 0?

2017-10-10 Thread Jay Guo
Yep. Thanks! cheers, - J On Tue, Oct 10, 2017 at 11:01 PM, Ian Lance Taylor wrote: > On Tue, Oct 10, 2017 at 7:56 AM, Jay Guo wrote: > > > > In my use case, both cases you presented are valid and I don't really > need > > to disambiguate them. So I guess calling `Wait` before `Add` here should

Re: [go-nuts] In `WaitGroup`, why should `Add(positive delta)` called before `Wait` if counter is 0?

2017-10-10 Thread Ian Lance Taylor
On Tue, Oct 10, 2017 at 7:56 AM, Jay Guo wrote: > > In my use case, both cases you presented are valid and I don't really need > to disambiguate them. So I guess calling `Wait` before `Add` here should be > fine? I couldn't tell if there would be any unexpected crash from reading > `WaitGroup` sou

Re: [go-nuts] Scope of variables with closures

2017-10-10 Thread Ian Lance Taylor
On Tue, Oct 10, 2017 at 7:22 AM, wrote: > > I'm trying to understand the scope of variables when using closures. > I wrote a simple program to compute fibonacci sequence with a closure (see > below). > Knowing that named return variables are initialized to 0 (when their type is > int), I tried to

Re: [go-nuts] In `WaitGroup`, why should `Add(positive delta)` called before `Wait` if counter is 0?

2017-10-10 Thread Jay Guo
Thanks for you reply! In my use case, both cases you presented are valid and I don't really need to disambiguate them. So I guess calling `Wait` before `Add` here should be fine? I couldn't tell if there would be any unexpected crash from reading `WaitGroup` source code. - J On Tue, Oct 10, 2017

[go-nuts] Scope of variables with closures

2017-10-10 Thread etienne . daspe
Hello, I'm trying to understand the scope of variables when using closures. I wrote a simple program to compute fibonacci sequence with a closure (see below). Knowing that named return variables are initialized to 0 (when their type is int), I tried to simplify my function ; but it doesn't comp

Re: [go-nuts] Library for implementing package matching similar to how "go build ./..." does it?

2017-10-10 Thread jimmy frasche
I have not used it personally but I believe this is what you are looking for: https://godoc.org/golang.org/x/tools/go/buildutil#ExpandPatterns On Mon, Oct 9, 2017 at 11:17 PM, wrote: > I'm looking for a library or function that implements the same logic that > many of Go's CLI tools do: > > go b

Re: [go-nuts] "defer go"

2017-10-10 Thread Bakul Shah
On Tue, 10 Oct 2017 09:27:52 -0400 Shawn Milochik wrote: Shawn Milochik writes: > > On Tue, Oct 10, 2017 at 9:13 AM, Scott Cotton wrote: > > > Hi all, > > > > 1. "defer go" extend defers to work on goroutine exit with mechanism > > just like defer, but if we say "defer go f()" > > instead of

Re: [go-nuts] "defer go"

2017-10-10 Thread Ian Lance Taylor
On Tue, Oct 10, 2017 at 6:27 AM, Shawn Milochik wrote: > On Tue, Oct 10, 2017 at 9:13 AM, Scott Cotton wrote: >> >> Hi all, >> >> 1. "defer go" extend defers to work on goroutine exit with mechanism >> just like defer, but if we say "defer go f()" >> instead of "defer f()" then we run on gorout

Re: [go-nuts] In `WaitGroup`, why should `Add(positive delta)` called before `Wait` if counter is 0?

2017-10-10 Thread Ian Lance Taylor
On Tue, Oct 10, 2017 at 5:34 AM, Jay Guo wrote: > > It is suggested in https://golang.org/pkg/sync/#WaitGroup that: > > // Note that calls with a positive delta that occur when the counter is zero > // must happen before a Wait. > > I wonder what's the reason in terms of `sync` implementation. > >

Re: [go-nuts] Re: Why are two slices in this example less costly than one?

2017-10-10 Thread Ian Lance Taylor
On Tue, Oct 10, 2017 at 12:50 AM, Gabriel Aszalos wrote: > > I would love to find out the answer to this. Even if you don't know the > answer but know how to investigate into it (using pprof or some tracing > flags), I would also appreciate being guided in the right direction and I > would love to

Re: [go-nuts] "defer go"

2017-10-10 Thread Ian Davis
On Tue, 10 Oct 2017, at 02:27 PM, Shawn Milochik wrote: > On Tue, Oct 10, 2017 at 9:13 AM, Scott Cotton labs.com> wrote:>> Hi all, >> >> 1. "defer go" extend defers to work on goroutine exit with >>mechanism just like defer, but if we say "defer go f()">> instead of >> "defer f()" then we

[go-nuts] "defer go"

2017-10-10 Thread Shawn Milochik
On Tue, Oct 10, 2017 at 9:13 AM, Scott Cotton wrote: > Hi all, > > 1. "defer go" extend defers to work on goroutine exit with mechanism > just like defer, but if we say "defer go f()" > instead of "defer f()" then we run on goroutine exit. Very big gains for > scaling here IMHO. > > You can al

[go-nuts] A few go 2 suggestions

2017-10-10 Thread Scott Cotton
Hi all, Been thinking about go 2 ideas, and I wanted to put forth some motivated but rough ideas. Here she goes: 1. "defer go" extend defers to work on goroutine exit with mechanism just like defer, but if we say "defer go f()" instead of "defer f()" then we run on goroutine exit. Very big

[go-nuts] Library for implementing package matching similar to how "go build ./..." does it?

2017-10-10 Thread mattmuelle
I'm looking for a library or function that implements the same logic that many of Go's CLI tools do: go build ./... go install ./... Where it will return a list of matched packages. I noticed that the code for this package matching is here: https://golang.org/src/cmd/go/internal/load/search.go

[go-nuts] In `WaitGroup`, why should `Add(positive delta)` called before `Wait` if counter is 0?

2017-10-10 Thread Jay Guo
Hi, It is suggested in https://golang.org/pkg/sync/#WaitGroup that: // Note that calls with a positive delta that occur when the counter is zero // must happen before a Wait. I wonder what's the reason in terms of `sync` implementation. Essentially I'm trying to implement following logic: for

[go-nuts] [ANN] GoCV - Computer Vision Using Go and OpenCV 3

2017-10-10 Thread Ron Evans
Hello, everyone Please allow me to introduce a new Go package: GoCV. GoCV provides bindings for Go that work with the latest version of OpenCV 3.3. We hope to make the Go programming language a “first-class” client compatible with the latest developments in the OpenCV ecosystem, just like Pytho

Re: [go-nuts] big.Int.SetString fails with string created with bytes.Buffer

2017-10-10 Thread Rob Pike
You almost never want bytes.NewBuffer. Its only purpose is to load a buffer with existing data to be read using Buffer.Read. -rob On Tue, Oct 10, 2017 at 8:14 PM, wrote: > Oh yes, thank you. I totally missed that, thinking the bytes.Buffer was > preallocated with 4 bytes, instead i filled it w

Re: [go-nuts] big.Int.SetString fails with string created with bytes.Buffer

2017-10-10 Thread aurelien . rainone
Oh yes, thank you. I totally missed that, thinking the bytes.Buffer was preallocated with 4 bytes, instead i filled it with 4x0 bytes Le mardi 10 octobre 2017 10:59:56 UTC+2, Ian Davis a écrit : > > > > > On Tue, 10 Oct 2017, at 09:51 AM, aurelien...@gmail.com > wrote: > > > func main() { > buf

Re: [go-nuts] big.Int.SetString fails with string created with bytes.Buffer

2017-10-10 Thread Ian Davis
On Tue, 10 Oct 2017, at 09:51 AM, aurelien.rain...@gmail.com wrote: > > func main() { > buf := bytes.NewBuffer(make([]byte, 4)) > buf.WriteString("1234") These two lines result in a string with 4 null bytes followed by 1234. Just use buf := &bytes.Buffer{} Ian -- You received this mess

[go-nuts] big.Int.SetString fails with string created with bytes.Buffer

2017-10-10 Thread aurelien . rainone
Hi everybody, I ran into this problem yesterday, I couldn't convert a string created with a bytes.Buffer into a big.Int by using SetString. On the other hand, with the same string value, created from literals or even from a byte slice, the conversion is successful. Find the code below or on th

[go-nuts] Re: Why are two slices in this example less costly than one?

2017-10-10 Thread Gabriel Aszalos
I would love to find out the answer to this. Even if you don't know the answer but know how to investigate into it (using pprof or some tracing flags), I would also appreciate being guided in the right direction and I would love to embark on the journey of finding out myself. What I'm basically