[go-nuts] lxn/walk goroutine blocks

2016-10-11 Thread Tamás Gulácsi
I suspect that the main thread has to communicate with the gui libs. This is a common restrictio. Live with it: do the other stuff in a goroutine. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

[go-nuts] go guru for Acme

2016-10-11 Thread Mathieu Lonjaret
Hi, Just a heads up for Acme users since it's not listed on https://docs.google.com/document/d/1_Y9xCEMj5S-7rv2ooHpZNH15JgRT5iM742gJkw5LtmQ/edit : I've modified the tool I'm using for my searches in acme (https://github.com/mpl/gofinder) so that it now supports Go guru. hth, Mathieu -- You rece

[go-nuts] Defer question

2016-10-11 Thread Henry
Hi, I stumbled upon this problem earlier and I wonder whether this is actually the intended behavior of defer or a bug. Here is the code to illustrate the problem (or you can view it in the Go playground at https://play.golang.org/p/s2hdAmirrl ). package main import ( "errors" "fmt" )

[go-nuts] Re: time representation to use with javascript

2016-10-11 Thread Caleb Doxsey
One thing you could try is to use two ints. One to represent seconds and the other nanoseconds. This is what protobuf does: https://github.com/golang/protobuf/blob/master/ptypes/timestamp.go. An ISO8601 string works too. On Monday, October 10, 2016 at 11:22:48 PM UTC-4, bsr wrote: > > Hello, >

Re: [go-nuts] Defer question

2016-10-11 Thread 'chris dollin' via golang-nuts
Your assignments in the deferred function are to the local variable `err`, not the return value of `Execute` -- you can't change the return value in the deferred function unless it has a name. You want to write func Execute() (err error) { defer func() { ... Now the return value is n

Re: [go-nuts] Defer question

2016-10-11 Thread Jan Mercl
On Tue, Oct 11, 2016 at 12:16 PM Henry wrote: This should work. func Execute() (err error) { defer func() { if err == nil { err = Commit() } if err != nil { Rollback() }

Re: [go-nuts] Marshal XML Mixed Content

2016-10-11 Thread Konstantin Khomoutov
On Mon, 10 Oct 2016 22:10:37 -0700 (PDT) Scott wrote: > I'm trying to Marshal XML where an element has mixed content: > https://www.w3.org/TR/REC-xml/#sec-mixed-content > > I tried just using []interface{} but if I put in just a string, > Marshal surrounds each string with the name of the slice

Fwd: [go-nuts] lxn/walk goroutine blocks

2016-10-11 Thread Pietro Gagliardi
> Begin forwarded message: > > From: Pietro Gagliardi > Subject: Re: [go-nuts] lxn/walk goroutine blocks > Date: October 11, 2016 at 7:48:04 AM EDT > To: Tamás Gulácsi > > That would mean lxn/walk is doing initialization on the init() thread, > because Windows does not care which thread you

[go-nuts] package versioning

2016-10-11 Thread Peter Vypov
This question has been asked here a number of times, but the last time a few months ago: are there any plans to add support for package versioning (understanding VCS tags in the import paths), that is to teach `go get` to pull specified version (tag) of the package rather than the most recent v

Re: [go-nuts] package versioning

2016-10-11 Thread Ian Lance Taylor
On Tue, Oct 11, 2016 at 12:30 AM, Peter Vypov wrote: > This question has been asked here a number of times, but the last time a few > months ago: are there any plans to add support for package versioning > (understanding VCS tags in the import paths), that is to teach `go get` to > pull specified

[go-nuts] Error when using go tool trace

2016-10-11 Thread xavier . ernest . zebier
Hello, I m trying to use the go tool trace. My code is package main import ( "flag" "fmt" "math" "net/http" "os" "runtime" "runtime/trace" "time" ) func indexHandler(w http.ResponseWriter, r *http.Request) { primesInRangeParallel(10, 64) fmt.Fprintf(w, "hello world, I'm running on %s with an %

[go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread T L
package main import "unsafe" import "sync/atomic" type T struct { a *int // no ways?! b unsafe.Pointer } func (t T) A() *int { // cannot take the address of unsafe.Pointer(t.a) //return (*int)(atomic.LoadPointer(&unsafe.Pointer(t.a))) return t.a // no ways to read t

[go-nuts] Re: no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread T L
More specifically, if I want to make the read/write of a pointer value atomically, then must the pointer value be defined as a value of type unsafe.Pointer? On Tuesday, October 11, 2016 at 10:26:21 PM UTC+8, T L wrote: > > package main > > import "unsafe" > import "sync/atomic" > > type T struct

Re: [go-nuts] Re: no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread Ian Lance Taylor
On Tue, Oct 11, 2016 at 7:29 AM, T L wrote: > More specifically, if I want to make the read/write of a pointer value > atomically, > then must the pointer value be defined as a value of type unsafe.Pointer? Yes. Ian -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread Jan Mercl
On Tue, Oct 11, 2016 at 4:26 PM T L wrote: package main import ( "sync/atomic" "unsafe" ) type T struct { a *int // no ways?! } func (t T) A() *int { return (*int)(atomic.LoadPointer

Re: [go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread T L
On Tuesday, October 11, 2016 at 10:42:02 PM UTC+8, Jan Mercl wrote: > > On Tue, Oct 11, 2016 at 4:26 PM T L > > wrote: > > package main > > import ( > "sync/atomic" > "unsafe" > ) > > type T struct { >

Re: [go-nuts] Re: no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread T L
On Tuesday, October 11, 2016 at 10:37:55 PM UTC+8, Ian Lance Taylor wrote: > > On Tue, Oct 11, 2016 at 7:29 AM, T L > > wrote: > > More specifically, if I want to make the read/write of a pointer value > > atomically, > > then must the pointer value be defined as a value of type > unsafe.Poi

Re: [go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread Jan Mercl
On Tue, Oct 11, 2016 at 4:55 PM T L wrote: > So values of type unsafe.Pointer can be converted to values of type *unsafe.Pointer? > But I can't find the official docs mentioning this. "Any pointer or value of underlying type uintptr can be converted to a Point

Re: [go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread Konstantin Khomoutov
On Tue, 11 Oct 2016 07:55:21 -0700 (PDT) T L wrote: [...] > > (*int)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&t.a > Wow, cool! > So values of type unsafe.Pointer can be converted to values of type > *unsafe.Pointer? > But I can't find the official docs mentioning this. Is it safe

Re: [go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread T L
On Tuesday, October 11, 2016 at 11:13:05 PM UTC+8, Konstantin Khomoutov wrote: > > On Tue, 11 Oct 2016 07:55:21 -0700 (PDT) > T L > wrote: > > [...] > > > (*int)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&t.a > > Wow, cool! > > So values of type unsafe.Pointer can be converted

Re: [go-nuts] no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread T L
On Tuesday, October 11, 2016 at 11:11:05 PM UTC+8, Jan Mercl wrote: > > On Tue, Oct 11, 2016 at 4:55 PM T L > > wrote: > > > So values of type unsafe.Pointer can be converted to values of type > *unsafe.Pointer? > > But I can't find the official docs mentioning this. > > "Any pointer or value o

Re: [go-nuts] Re: [ANN] gorram: like go run for any* function in stdlib or GOPATH

2016-10-11 Thread Edward Muller
gorram -r <...> On Mon, Oct 10, 2016 at 3:02 PM Mathieu Lonjaret wrote: > Looks shiny! > But is there some sort of cache I have to clear? I've just updated and > rebuilt, and I still get the old behaviour. > > > On 8 October 2016 at 04:05, Nate Finch wrote: > > ...and now it works like you'd ho

Re: [go-nuts] Marshal XML Mixed Content

2016-10-11 Thread smw12
Sorry, I should have been more clear. The reason I used a slice was because I need an arbitrary number of elements. So I can't just use a static struct with the chardata tags. On Tuesday, October 11, 2016 at 4:49:34 AM UTC-7, Konstantin Khomoutov wrote: > > On Mon, 10 Oct 2016 22:10:37 -0700 (

[go-nuts] Architect a daemon program

2016-10-11 Thread Tong Sun
I've searched the mlist archive and have learned that I should avoid daemonize as much as possible. So instead of label my program as a daemon (or singleton or anything), let me describe what I need to do. I need the program (say, named as`myprog`) to fork into the background (if possible) wit

Re: [go-nuts] Marshal XML Mixed Content

2016-10-11 Thread smw12
I figured out a solution: https://play.golang.org/p/sWR1hAumYh I created a type that wraps string and implements the xml.Marshaler interface. Then I just cast my strings to that type. Hey go team, any chance this could be made the default behavior for xml.CharData types so a single cast would

Re: [go-nuts] Marshal XML Mixed Content

2016-10-11 Thread Konstantin Khomoutov
On Tue, 11 Oct 2016 10:12:50 -0700 (PDT) sm...@brillig.org wrote: [...] > >> > I'm trying to Marshal XML where an element has mixed content: > >> > https://www.w3.org/TR/REC-xml/#sec-mixed-content > >> > > >> > I tried just using []interface{} but if I put in just a string, > >> > Marshal surr

Re: [go-nuts] Marshal XML Mixed Content

2016-10-11 Thread Konstantin Khomoutov
On Tue, 11 Oct 2016 10:00:33 -0700 (PDT) sm...@brillig.org wrote: [...] > > > I'm trying to Marshal XML where an element has mixed content: > > > https://www.w3.org/TR/REC-xml/#sec-mixed-content > > > > > > I tried just using []interface{} but if I put in just a string, > > > Marshal surrounds

Re: [go-nuts] Architect a daemon program

2016-10-11 Thread Peter Mogensen
On 2016-10-11 19:09, Tong Sun wrote: I need the program (say, named as`myprog`) to fork into the background (if possible) with the "start" command-line option. What's important is that when `myprog` is called with other command-line options, it will /communicate with the running background proc

Re: [go-nuts] Re: [ANN] gorram: like go run for any* function in stdlib or GOPATH

2016-10-11 Thread Mathieu Lonjaret
aha! that was it, thanks. On 11 October 2016 at 18:16, Edward Muller wrote: > gorram -r <...> > > On Mon, Oct 10, 2016 at 3:02 PM Mathieu Lonjaret > wrote: >> >> Looks shiny! >> But is there some sort of cache I have to clear? I've just updated and >> rebuilt, and I still get the old behaviour.

[go-nuts] Survey - do you use Go in the cloud?

2016-10-11 Thread 'Andrew Jessup' via golang-nuts
Hi Gophers, I'm on the Cloud Platform group at Google. We're trying to understand what kinds of services Go developers are building that they plan to host with a third party provider (any provider, not just Google) and why they picked Go for doing so. As such we're putting up a short (no, rea

[go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-11 Thread hiatt . dustin
The runtime.Gosched in the spin lock is going to be quite expensive. I found it's best to only do that every once and awhile, maybe every 100 iterations of the loop or so (you'll want to find optimal for your case). On Tuesday, October 4, 2016 at 4:09:30 AM UTC-5, sphil...@gmail.com wrote: > >

Re: [go-nuts] fmt.Printf not respecting String() method of elements of a struct

2016-10-11 Thread sbkim via golang-nuts
On Friday, October 7, 2016 at 4:57:29 PM UTC-7, Ian Lance Taylor wrote: > > On Fri, Oct 7, 2016 at 4:18 PM, sbkim via golang-nuts > > wrote: > > > > If an operand of fmt.Printf implements method String() string, > fmt.Printf > > respects it and uses it. > > But it doesn't if an operand is a a

Re: [go-nuts] Re: [ANN] gorram: like go run for any* function in stdlib or GOPATH

2016-10-11 Thread Nate Finch
Next on my list is adding versioning to the generated scripts so you never have to worry about whether a script is old or not. Also note that I added -t so you can print out different parts of the respond if you want, e.g. $ gorram -t {{.Status}} net/http Get https://golang.org 200 OK On Mo

Re: [go-nuts] Re: no ways to atomically read values, other than intergers, if unsafe.Pointer and atomic.Value are not considered?

2016-10-11 Thread Ian Lance Taylor
On Tue, Oct 11, 2016 at 8:06 AM, T L wrote: > > On Tuesday, October 11, 2016 at 10:37:55 PM UTC+8, Ian Lance Taylor wrote: >> >> On Tue, Oct 11, 2016 at 7:29 AM, T L wrote: >> > More specifically, if I want to make the read/write of a pointer value >> > atomically, >> > then must the pointer valu

[go-nuts] Reading http.Request.Body...

2016-10-11 Thread forfader
I'm reading the Body of an HTTP request. In my handler I want to chunk the response body up into fixed size blocks. I doing this using the following code: b := make([]byte, config.Blocksize) for { cnt, err := r.Body.Read(b) if err == io.EOF { break } if err != nil { log.Error("Re

Re: [go-nuts] Reading http.Request.Body...

2016-10-11 Thread Andy Balholm
I think what you need is io.ReadFull. Andy -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit http

[go-nuts] Group and Sum slices

2016-10-11 Thread Marcos Bortolussi
Hi, I come from the .NET world where I had LINQ so i could do in memory queries like the one we usually see in SQL. I have a slice of this structure I want to group by 8 fields, and then sum another integer field. Something like: type Register struct { id1 int id2 int id3 int id4 int id5 int id

[go-nuts] do I need nested maps to have mentioned output. new to golang please help

2016-10-11 Thread dhaneshmane123
I need following output [ { date:'2017-07-07', flags: { a:1 b:2 } }, { date:'2017-07-08', flags: { a:3 b:4 } } ] so I am trying to do it as follows but not getting desired output, can some one suggest right approach. type main struct{ d

[go-nuts] Re: do I need nested maps to have mentioned output. new to golang please help

2016-10-11 Thread Roberto Zanotto
"main" is also the name of the main function, maybe try with a different one. On Tuesday, October 11, 2016 at 11:54:54 PM UTC+2, Dan wrote: > > I need following output > [ > { > date:'2017-07-07', > flags: { > a:1 > b:2 > } > }, > { > date:'2017-07-08', > fl

[go-nuts] Re: Reading http.Request.Body...

2016-10-11 Thread forfader
Thank you. I figured there was such a function. Just couldn't find it. Michael- On Tuesday, October 11, 2016 at 2:31:41 PM UTC-7, forfader wrote: > > I'm reading the Body of an HTTP request. In my handler I want to chunk the > response body up into fixed size blocks. I doing this using the follo

Re: [go-nuts] Re: Reading http.Request.Body...

2016-10-11 Thread Edward Muller
There is also ReadAtLeast (https://golang.org/pkg/io/#ReadAtLeast) On Tue, Oct 11, 2016 at 3:13 PM forfader wrote: > Thank you. I figured there was such a function. Just couldn't find it. > > Michael- > > > On Tuesday, October 11, 2016 at 2:31:41 PM UTC-7, forfader wrote: > > I'm reading the Bod

[go-nuts] Determine DNS Server Responding

2016-10-11 Thread whydoit100
I'm new to Go so please forgive the newbie question. Is there a way with one of the Go libraries which will indicate which name server is responding to a host lookup request ? I have looked at the dns and net libraries but I have not found a function that will return the name server responding.

Re: [go-nuts] Determine DNS Server Responding

2016-10-11 Thread Jonathan Yu
On Tue, Oct 11, 2016 at 3:56 PM, wrote: > I'm new to Go so please forgive the newbie question. > > Is there a way with one of the Go libraries which will indicate which name > server is responding to a host lookup request ? > > I have looked at the dns and net libraries but I have not found a fun

[go-nuts] Re: package versioning

2016-10-11 Thread 'Eric Johnson' via golang-nuts
On Tuesday, October 11, 2016 at 5:55:23 AM UTC-7, Peter Vypov wrote: > > This question has been asked here a number of times, but the last time a > few months ago: are there any plans to add support for package versioning > (understanding VCS tags in the import paths), that is to teach `go get`

[go-nuts] Re: Group and Sum slices

2016-10-11 Thread Caleb Doxsey
Go doesn't have LINQ, but it does have a database/sql package. If you're not afraid of using strings, probably the cleanest way to do this would be to use sqlite, an embedded database, that understands SQL and has support for in-memory tables. Here's a go binding: https://godoc.org/github.com/m

[go-nuts] infinite loop makes program stuck

2016-10-11 Thread liminglangjun
Hi, there. I've read the FAQ and specifically the concurrency part. Tell me if the problem has been discussed anywhere. I used an infinite loop to block a goroutine until a value is big enough: for commitIndex < index {} I know its bad but its just a very intuitive and fast to implement. And I

Re: [go-nuts] infinite loop makes program stuck

2016-10-11 Thread Ian Lance Taylor
On Tue, Oct 11, 2016 at 7:26 PM, wrote: > Hi, there. I've read the FAQ and specifically the concurrency part. Tell me > if the problem has been discussed anywhere. > > I used an infinite loop to block a goroutine until a value is big enough: > > for commitIndex < index {} > > I know its bad but i

[go-nuts] Error handling and structured logging

2016-10-11 Thread John Jeffery
I have been following the progress of package github.com/pkg/errors, and have put it to much use. Thanks very much to Dave Cheney and the other authors. A few months ago an interesting issue was raised along the lines of being able to attach arbitrary data to the error (https://github.com/pkg/

Re: [go-nuts] infinite loop makes program stuck

2016-10-11 Thread Jesse McNelis
On Wed, Oct 12, 2016 at 1:26 PM, wrote: > These are the only two places that access commitIndex. I didn't acquire the > lock when reading commitIndex since I think its OK to read a stale value in > my case. Remember that locking is communication. Saying, "I never poll the http server, it's ok if

Re: [go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-11 Thread Henrik Johansson
But do these types of spin locks provide the same memory effects as standard locks? I get that only one goroutine at a time can run the given block but assigning to shared vars inside the block will still need to use the methods from sync/atomic right? On Tue, Oct 11, 2016, 22:47 wrote: > The ru

Re: [go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-11 Thread hiatt . dustin
You should only mutate variables inside the block that you are protecting with the locks, in this regard they are similar to the mutexes in the standard library. Be careful with the spin locks though, I would only use them where low latency is an absolute must, your go routines will sit there

Re: [go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-11 Thread Henrik Johansson
Yes I get that but it seems as there other constraints at play here wrt the memory model. In essence the spin locks (unless described outside their code somewhere) state that one measly atomic load has the same memory effects as a sync/lock which seems like it might work on some platforms (maybe)

[go-nuts] Re: Suggestions for parsing Forwarded HTTP Header (RFC 7239)

2016-10-11 Thread Tim Heckman
Hi Gophers! I ended up implementing a package for parsing the header. It didn't seem like there was anything else purpose-built for it: * https://github.com/theckman/httpforwarded Any feedback on the code, or the project in general, is welcome. Cheers! -Tim On Saturday, October 8, 2016 at 12:

Fwd: [go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-11 Thread Henrik Johansson
Forgot the list, sorry. -- Forwarded message - From: Henrik Johansson Date: ons 12 okt. 2016 kl 08:32 Subject: Re: [go-nuts] Re: Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock() To: Dustin Hiat