[go-nuts] Re: looking for a hot reloader/producer package

2016-10-03 Thread Egon
On Tuesday, 4 October 2016 00:57:57 UTC+3, mhh...@gmail.com wrote: > > Hi, > > I ll sleep on your code to digest it again. > > Yet agree i should not have these shared Registry, > and that your tree walk is way simpler. > > I may have some disagreements about 0 and 1, but it does not worth > me

[go-nuts] go closure escape analysis

2016-10-03 Thread 刘桂祥
// example1.go package main func main() { var y int // BAD: y escapes func(p *int, x int) { *p = x }(&y, 42) } example1.go y escape to the heap // example2.go package main func main() { var y int func(x int) { y = x }(42) } example2.go y is not escaped and why ?? // example3.go

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

2016-10-03 Thread Sokolov Yura
Try this: func (store *Store) addToStore(destination map[string]*Distribution, key string, value int64) { store.lock.Lock() distribution, exists := destination[key] if !exists { store.lock.Unlock() distribution = NewDistribution() distributio

Re: [go-nuts] Re: How to initialize all members of a slice

2016-10-03 Thread Lars Seipel
On Mon, Oct 03, 2016 at 04:19:34PM -0700, C Banning wrote: > Lot's of people will jump up and down that this is "unsafe," but if you're > building a utility and have complete control of the code something like > this might work: https://play.golang.org/p/eDPoI83C0u Not necessarily unsafe, just u

Re: [go-nuts] `go test` does not honor -ldflags

2016-10-03 Thread Ian Lance Taylor
On Mon, Oct 3, 2016 at 4:08 PM, wrote: > > Please see the code of main.go and main_test.go pasted at the end. Then > consider the output of these commands. I would have expected the `go test` > command's output to contain the value 'hello'. From `go help test` output, > the `go test` command is s

[go-nuts] `go test` does not honor -ldflags

2016-10-03 Thread singh . gurjeet
Please see the code of main.go and main_test.go pasted at the end. Then consider the output of these commands. I would have expected the `go test` command's output to contain the value 'hello'. From `go help test` output, the `go test` command is supposed to honor all build flags, but clearly i

[go-nuts] Re: How to initialize all members of a slice

2016-10-03 Thread C Banning
Lot's of people will jump up and down that this is "unsafe," but if you're building a utility and have complete control of the code something like this might work: https://play.golang.org/p/eDPoI83C0u On Sunday, October 2, 2016 at 10:39:08 PM UTC-6, Sarah Ahmed wrote: > > Hello, > I am trying to

[go-nuts] Re: looking for a hot reloader/producer package

2016-10-03 Thread mhhcbon
Hi, I ll sleep on your code to digest it again. Yet agree i should not have these shared Registry, and that your tree walk is way simpler. I may have some disagreements about 0 and 1, but it does not worth mentioning, its all very contextual. thanks! -- You received this message because you

Re: [go-nuts] can't understand sync.RWMutex documentation

2016-10-03 Thread Roberto Zanotto
I get it now. Thanks for your time. On Monday, October 3, 2016 at 10:55:34 PM UTC+2, Caleb Spare wrote: > > It's explained in the text afterwards: > > "This is to ensure that the lock eventually becomes available; a > blocked Lock call excludes new readers from acquiring the lock." > > So if yo

[go-nuts] godoc "Error communicating with remote server."

2016-10-03 Thread Frank Davidson
Hi, I'm running godoc in the following manner: nohup ./godoc -http=:8071 -goroot=/godoc -play=true & but when I try to play the examples in my docs in the Playground I'm getting the error: "Error communicating with remote server." Are there ports or anything I have to have open? I would think

[go-nuts] Re: looking for a hot reloader/producer package

2016-10-03 Thread Egon
On Monday, 3 October 2016 20:55:45 UTC+3, mhh...@gmail.com wrote: > > Hi, > > I m looking for a package which would call a producer when a fs event is > emitted. > > Doing so i could reload templates everytime they changed without > restarting the app. > Based on complexity: 1. For template

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

2016-10-03 Thread Nate Finch
get it via the canonical import path: go get npf.io/gorram Code is at https://github.com/natefinch/gorram Still a work in progress, but fun to play around with right now. Lets you do things like this: $ echo 12345 | gorram encoding/base64.StdEncoding.EncodeToString MTIzNDU2Cg== or $

Re: [go-nuts] can't understand sync.RWMutex documentation

2016-10-03 Thread Caleb Spare
It's explained in the text afterwards: "This is to ensure that the lock eventually becomes available; a blocked Lock call excludes new readers from acquiring the lock." So if you RLock and then another goroutine tries to Lock, you might not be able to RLock again until the first read lock is RUnl

[go-nuts] can't understand sync.RWMutex documentation

2016-10-03 Thread Roberto Zanotto
Hi everyone. I thought I understood clearly how an RWMutex is supposed to work, but the documentation is giving me some troubles. It says: "The lock can be held by an arbitrary number of readers" which is fine by me, but then the following statement seems to contradict it: "If a goroutine holds

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread 'Srimanth Gunturi' via golang-nuts
Now it is making more sense. So GOMAXPROCS has no connection with the actual number of OS threads created to run goroutines. But it does determine how many of them are active at any given time. Also, a single OS thread can multiplex multiple goroutines, unless #LockOSThread() is invoked in which ca

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread Ian Lance Taylor
On Mon, Oct 3, 2016 at 12:48 PM, 'SrimanthG' via golang-nuts wrote: > I have another code snippet which hits the same problem and it does not use > sleep: https://play.golang.org/p/mUPCOFle4h > All 10 goroutines are going beyond "runtime.LockOSThread()" on a single OS > thread. No, they are not.

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread Ian Lance Taylor
On Mon, Oct 3, 2016 at 12:24 PM, 'SrimanthG' via golang-nuts wrote: > > Do you mean to say that as long as the process is running instructions, it > will not let any other goroutine use that OS thread and execute? It's either somewhat simpler or much more complex than that. It is simpler in the

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread 'SrimanthG' via golang-nuts
I have another code snippet which hits the same problem and it does not use sleep: https://play.golang.org/p/mUPCOFle4h All 10 goroutines are going beyond "runtime.LockOSThread()" on a single OS thread. Output: > main > locked 1 > locked 10 > locked 9 > locked 8 > locked 7 > locked 6 > locked 5

[go-nuts] Re: looking for a hot reloader/producer package

2016-10-03 Thread mhhcbon
A quick&dirty implementation would look likes this https://gist.github.com/mh-cbon/9eb7701e57a8f37bb7e62647dc9726e8 And for my last Q, http://stackoverflow.com/questions/21447463/is-assigning-a-pointer-atomic-in-golang If you have anything battled tested pkg i d be happy to see it in action! -

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread 'SrimanthG' via golang-nuts
Thank you for pointing that out. Do you mean to say that as long as the process is running instructions, it will not let any other goroutine use that OS thread and execute? If so, can the documentation be updated to mention sleeping as cause for letting other goroutines in. Also, what other ca

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread Ian Lance Taylor
On Mon, Oct 3, 2016 at 12:10 PM, 'SrimanthG' via golang-nuts wrote: > If you run the code snippet I pasted in https://play.golang.org/p/4R-WlCiKNT > you will see that it runs both in parallel - hence my confusion Sleeping in time.Sleep does not count as running. If you mean something else, can y

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread 'SrimanthG' via golang-nuts
If you run the code snippet I pasted in https://play.golang.org/p/4R-WlCiKNT you will see that it runs both in parallel - hence my confusion On Monday, October 3, 2016 at 12:04:39 PM UTC-7, Ian Lance Taylor wrote: > > On Mon, Oct 3, 2016 at 11:31 AM, 'SrimanthG' via golang-nuts > > wrote: >

Re: [go-nuts] runtime.LockOSThread() question

2016-10-03 Thread Ian Lance Taylor
On Mon, Oct 3, 2016 at 11:31 AM, 'SrimanthG' via golang-nuts wrote: > > I ran a Go program with GOMAXPROCS=1 and two goroutines which both did > "runtime.LockOSThread()" and slept 10 seconds before exiting. > > Code: https://play.golang.org/p/4R-WlCiKNT > > Since I had 1 OS thread and 2 goroutines

Re: [go-nuts] Correct use of Mutex

2016-10-03 Thread Edward Muller
type Foo struct { sync.RWMutex data map[string]bool } o := &Foo{} o.Lock() o.data[i] = true o.Unlock() elsewhere o.RLock() v := o.data[i] o.RUnlock() On Mon, Oct 3, 2016 at 11:55 AM wrote: > > Which is correct? > > o.Lock() > o.data[i] = true > o.Unlock() > > or > > o.Lock() > i.RLoc

Re: [go-nuts] SWIG and anonymous field inheritance

2016-10-03 Thread Ian Lance Taylor
On Sun, Oct 2, 2016 at 2:03 AM, Shengqiu Li wrote: > > I'm making a binding of a C++ library for go, and I'm wondering why the > anonymous field inheritance isn't used in the go wrapper code. > > I have found a piece of comment in the go backend of SWIG, saying: > >> // For each method defin

Re: [go-nuts] encode struct as JSON, and use it in http.NewRequest ( io.Writer vs. io.Reader issue )H

2016-10-03 Thread Edward Muller
See also https://golang.org/pkg/io/#Pipe On Sat, Oct 1, 2016 at 9:13 PM Shawn Milochik wrote: > How about https://golang.org/pkg/bytes/#NewReader ? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop

[go-nuts] Correct use of Mutex

2016-10-03 Thread alex
Which is correct? o.Lock() o.data[i] = true o.Unlock() or o.Lock() i.RLock() o.data[i] = true i.RUnlock() o.Unlock() The latter actually seems to help high contention R/W operations on a very large map according to the guy in my team who was working on the problem, but I would have thought t

[go-nuts] runtime.LockOSThread() question

2016-10-03 Thread 'SrimanthG' via golang-nuts
Hello, I ran a Go program with GOMAXPROCS=1 and two goroutines which both did "runtime.LockOSThread()" and slept 10 seconds before exiting. Code: https://play.golang.org/p/4R-WlCiKNT Since I had 1 OS thread and 2 goroutines trying to lock an OS thread, I was expecting only one of them to comple

[go-nuts] Re: how create a go app win, linux of etc ?????

2016-10-03 Thread egorsmkv
See to this project -- https://github.com/visualfc/goqt понедельник, 3 октября 2016 г., 16:35:54 UTC+3 пользователь hadies...@gmail.com написал: > > hi guys > > i am new in go, and i do not now how to create a windows app > > please guide me > > > -thank you > -- You received this message becau

[go-nuts] Re: how create a go app win, linux of etc ?????

2016-10-03 Thread hadiesmaili85
mean is : i want create application for window or others platforms On Monday, October 3, 2016 at 10:58:26 AM UTC-7, mhh...@gmail.com wrote: > > Hi, > > what do you mean by windows app ? > > If you want build an exe for windows, > check http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-

Re: [go-nuts] calling go functions from c

2016-10-03 Thread Ian Lance Taylor
On Sun, Oct 2, 2016 at 2:37 PM, wrote: >> There is some overhead when using gccgo, because of the need to >> interact with the Go scheduler. The overhead should be slightly less. > > > Any idea what (very rough is fine) that overhead is when compared to the > standard go toolchain? I've never m

[go-nuts] Re: how create a go app win, linux of etc ?????

2016-10-03 Thread mhhcbon
Hi, what do you mean by windows app ? If you want build an exe for windows, check http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5 If you want to build a go app using windows gui framework, I could not say for sure, i never did that myself, you can try to dig https://www.google.co

[go-nuts] looking for a hot reloader/producer package

2016-10-03 Thread mhhcbon
Hi, I m looking for a package which would call a producer when a fs event is emitted. Doing so i could reload templates everytime they changed without restarting the app. I ve found this package https://github.com/gernest/hot But, its totally built to render templates, where as i know i ll ad

[go-nuts] Re: json package error ?

2016-10-03 Thread 刘湃
Try this https://play.golang.org/p/54Utd1Vsw3 https://godoc.org/encoding/json#Marshal String values encode as JSON strings coerced to valid UTF-8, replacing invalid bytes with the Unicode replacement rune. The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e" to keep some browsers

Re: [go-nuts] method type

2016-10-03 Thread 'Jyotiswarup Raiturkar' via golang-nuts
Cool. thanks! -Jyotiswarup Raiturkar On Mon, Oct 3, 2016 at 9:10 PM, Axel Wagner wrote: > Yes, you are pretty much there, but you are using t, which is a variable > of the type (so the method has an already bound receiver and is thus of > type func()), instead you need to reference the method o

Re: [go-nuts] Overflow behavior guarantees for atomic.Add*

2016-10-03 Thread 'Axel Wagner' via golang-nuts
According to the godoc : The add operation, implemented by the AddT functions, is the atomic > equivalent of: > >> *addr += delta >> return *addr > > which provides a guarantee of the correct overflow behavior. On Mon, Oct 3, 2016 at 5:45 PM, Caleb Spare wrote: >

Re: [go-nuts] Overflow behavior guarantees for atomic.Add*

2016-10-03 Thread Caleb Spare
> I'm familiar with (and greatly appreciate!) the guarantees regarding > overflow for ordinary integer arithmetic in the Go spec Which guarantees? > but I've been > unable to locate anything that reassures me that similar guarantees apply > for the sync/atomic.Add* functions. Is there any officia

Re: [go-nuts] method type

2016-10-03 Thread 'Axel Wagner' via golang-nuts
Yes, you are pretty much there, but you are using t, which is a variable of the type (so the method has an already bound receiver and is thus of type func()), instead you need to reference the method on *Test itself, which has the correct signature: https://play.golang.org/p/NKGBDse-9n On Mon, Oct

Re: [go-nuts] json package error ?

2016-10-03 Thread Konstantin Khomoutov
On Mon, 3 Oct 2016 04:57:08 -0700 (PDT) Marcin Jurczuk wrote: > > > > > I hit some issue with son.Marshal string parsing and I don't > > > > > know is it package error or "this is not a bug - it's a > > > > > feature". > > > > > > > > > > Here is code that doesn't work like expected: > > > > >

[go-nuts] method type

2016-10-03 Thread 'Jyotiswarup Raiturkar' via golang-nuts
Hello All, Is it possible to define a type for a method . Something like below for f Arent methods basically syntactic sugar for functions? type Test struct { A string } func (t *Test) P() { fmt.Println(t.A) } type AttribSetter func(t *Test) var f AttribSetter t := &Test{"meow"} f = AttribS

[go-nuts] Re: How to initialize all members of a slice

2016-10-03 Thread Val
Hello Sarah, I managed to run something implementing json.Unmarshaler : see code on playground There are probably better/cleaner ways of doing that, suggestions welcome. Please note : - the pointer receiver (a *Address) - the local type AddressGhost, just to

Re: [go-nuts] How to initialize all members of a slice

2016-10-03 Thread 'Axel Wagner' via golang-nuts
There is no way to do this but using a for-loop. In this case, it probably means adding for i, a := range p.Adr { if a.State == "" { a.State = "NY" p.Adr[i] = a } } before the last fmt.Printf. On Mon, Oct 3, 2016 at 4:57 AM, Sarah Ahmed wrote: > Hello, > I am trying to

[go-nuts] how create a go app win, linux of etc ?????

2016-10-03 Thread hadiesmaili85
hi guys i am new in go, and i do not now how to create a windows app please guide me -thank you -- 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+un

Re: [go-nuts] json package error ?

2016-10-03 Thread Marcin Jurczuk
I'm getting text strings like "Cisco device <>", then they are converted do JSON, and at some point one of task is to log them again as a string by calling string(json_obj). Here is problem since in logs hey all appear as \u003c\u003 instead of << or >>. W dniu poniedziałek, 3 października 20

Re: [go-nuts] json package error ?

2016-10-03 Thread Konstantin Khomoutov
On Mon, 3 Oct 2016 03:35:15 -0700 (PDT) Marcin Jurczuk wrote: > > > I hit some issue with son.Marshal string parsing and I don't know > > > is it package error or "this is not a bug - it's a feature". > > > > > > Here is code that doesn't work like expected: > > > https://play.golang.org/p/vAO

Re: [go-nuts] json package error ?

2016-10-03 Thread Marcin Jurczuk
Thanks, In the mean time I've founded that it has to do with HTML injections. Question remains how in go get rid/disable this protection ? I'm getting this data from SNMP communication and I have to parse them, display and store. I didn't found in json library any method to handle such "protect

Re: [go-nuts] How to define two identical named types?

2016-10-03 Thread T L
On Monday, October 3, 2016 at 5:30:35 PM UTC+8, Axel Wagner wrote: > > The only difference between talking about "TypeDecl" and "TypeSpec" is, > that it distinguishes > > type ( > Foo int > Bar int > ) > > from > > type Foo int > type Bar int > ok, it looks the misunderstanding comes I

Re: [go-nuts] json package error ?

2016-10-03 Thread 'chris dollin' via golang-nuts
On 3 October 2016 at 10:16, Marcin Jurczuk wrote: > Hi, > > I hit some issue with son.Marshal string parsing and I don't know is it > package error or "this is not a bug - it's a feature". > > Here is code that doesn't work like expected: > https://play.golang.org/p/vAOhLCtoSh > > > Why I'm gettin

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

2016-10-03 Thread Konstantin Shaposhnikov
I don't think defer is the main bottleneck here. I tested the benchmark with Go tip and with removing defers. While it becomes faster it is still slower than Java. I believe that the reason the Java version is faster is that it's lock implementation behaves better under contention. While I am not

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

2016-10-03 Thread toefel18
Hi Jesper, Thanks for the good explanation :). The Java optimization techniques can explain the difference in performance. I now realize that the Java performance in production (a web application) will be worse than in the benchmark because lock elision and coarsening will most likely not be p

Re: [go-nuts] How to define two identical named types?

2016-10-03 Thread 'Axel Wagner' via golang-nuts
The only difference between talking about "TypeDecl" and "TypeSpec" is, that it distinguishes type ( Foo int Bar int ) from type Foo int type Bar int so I don't see how it helps and if anything it makes things more confusing, because one type declaration can *actually* define multiple t

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

2016-10-03 Thread Florin Pățan
Not only that defer but also the ones in the benchmark code itself. See this: diff --git a/gopatanbench/benchmark.go b/gopatanbench/benchmark.go index 23503a9..e92ed88 100644 --- a/gopatanbench/benchmark.go +++ b/gopatanbench/benchmark.go @@ -37,13 +37,13 @@ func Benchmrk(threads int64, itemsPerT

[go-nuts] json package error ?

2016-10-03 Thread Marcin Jurczuk
Hi, I hit some issue with son.Marshal string parsing and I don't know is it package error or "this is not a bug - it's a feature". Here is code that doesn't work like expected: https://play.golang.org/p/vAOhLCtoSh Why I'm getting \u003c\u003 instead of << when printing printing out json ?? --

Re: [go-nuts] How to define two identical named types?

2016-10-03 Thread T L
On Monday, October 3, 2016 at 4:59:26 PM UTC+8, T L wrote: > > > > On Monday, October 3, 2016 at 2:42:30 PM UTC+8, Axel Wagner wrote: >> >> Which would imply that something like this >> type ( >> Foo int >> Foo int >> ) >> might be legal. I don't understand (and thusly disagree) why that

Re: [go-nuts] How to define two identical named types?

2016-10-03 Thread T L
On Monday, October 3, 2016 at 2:42:30 PM UTC+8, Axel Wagner wrote: > > Which would imply that something like this > type ( > Foo int > Foo int > ) > might be legal. I don't understand (and thusly disagree) why that would be > in any sense "less confusing". > I confuse again. In your b

Re: [go-nuts] time.Since()

2016-10-03 Thread Alexander Kapshuk
On Mon, Oct 3, 2016 at 11:00 AM, wrote: > hi guys > > i can't undrestand this func, can you say example for this func : > > time.Since() > > thank you > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and sto

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

2016-10-03 Thread Aliaksandr Valialkin
I bet the bottleneck is exactly at defer. Good news - it looks like go 1.8 will have much faster defer and, as a bonus, faster cgo calls: - https://github.com/golang/go/commit/f8b2314c563be4366f645536e8031a132cfdf3dd - https://github.com/golang/go/commit/441502154fa5f78e93c9c7985fbea78a02c21f4f

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

2016-10-03 Thread toefel18
Thanks for the tip, I rewrote it using explicit locking and it indeed results in much better performance, still far from Java. but the next response gives a good explanation why that can happen. On Sunday, October 2, 2016 at 8:33:15 PM UTC+2, Justin Israel wrote: > > Do you get better performan

[go-nuts] time.Since()

2016-10-03 Thread hadiesmaili85
hi guys i can't undrestand this func, can you say example for this func : time.Since() thank you -- 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+un