Re: [go-nuts] Is there a "strings.Clone(string) string" alike function?

2017-02-06 Thread T L


On Friday, February 3, 2017 at 10:54:59 PM UTC+8, rog wrote:
>
> This program reports only one allocation per operation, which seems 
> to indicate that your solution is already the right one: 
>
> https://play.golang.org/p/Fx1EMYKRRd 
>
>
>
Yes, but only for small strings with length <= 32

https://play.golang.org/p/TfdahRKVr3

 

> On 1 February 2017 at 09:18, T L  wrote: 
> > Sometimes, I want to create a new string which will not share the 
> underlying 
> > bytes with other strings. 
> > For example, to avoid the substring memory leak problem. 
> > 
> > newStr := string([]byte(oldStr)) is simple but will make two memory 
> > allocations, and one of them is a waste. 
> > 
> > There are two solutions which only make one memory allocation in 
> > https://groups.google.com/forum/#!topic/golang-nuts/naMCI9Jt6Qg 
> > (code: https://play.golang.org/p/3rVsMTaHUz). 
> > But in that thread, someone said the two are not safe from being 
> optimized 
> > unexpectedly in later compiler versions. 
> > 
> > I found the most approached function in the standard lib is 
> > strings.Repeat(), but it also makes two memory allocations. 
> > 
> > Is there a safe way to do this with only one memory allocation? 
> > 
> > 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Is there something wrong with performance of select in a for loop

2017-02-06 Thread Chris Holland
Well you're waiting in the select... so yeah its going to be at the top.

The tickers themselves take up quite a bit of resources, in a little test 
like this.

I adjusted your test to remove all the tickers, and got about 4x the speed. 
I also set GOMAXPROCS to 1 gives it a better case against node. I made the 
cpuprofile flag controlled. Then also ran the tests descending, to see if 
being "warm" did anything.

I attached the changes if you want to try them out. The tickers were the 
real hogs. On my vm the times look like

1 69.655702ms
2 122.78818ms
3 149.580323ms
4 158.053242ms
5 153.452385ms
6 200.548673ms
5 160.500261ms
4 134.539412ms
3 117.446786ms
2 125.365ms
1 132.77861ms


-Chris

On Sunday, February 5, 2017 at 11:00:15 AM UTC-8, fwan...@gmail.com wrote:
>
> I make a test to see the performance of select, and found the result is 
> not good.
>
> I make 1000 SeqQueue objects and run its messageLoop function (which does 
> a small piece of work, and is listed as below) in 1000 separate go 
> routines. The CPU cost is more than 20%.
> If I make the ticker 1 second, the CPU cost can slow down to about 2%.
>
> With pprof, I see the most top cost are methods related to 
> runtime.selectGo, runtime.lock.
>
> Who knows is there anything wrong in my case?
>
> func (this *SeqQueue) messageLoop() {
> var ticker = time.NewTicker(100 * time.Millisecond)
> defer ticker.Stop()
> for {
> select {
> case <-serverDone:
> return
> case <-this.done:
> return
> case <-ticker.C:
> this.tickCounter += 1
> case message := <-this.messages:
> this.messageCounter += 1
> _ = message
> }
> }
> }
>
>
>
>

-- 
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 https://groups.google.com/d/optout.


waitcond.go
Description: Binary data


test.go
Description: Binary data


[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Jason E. Aten
On Monday, February 6, 2017 at 11:55:21 PM UTC-6, Dave Cheney wrote:
>
> I think there are more data races in your product
>

Thanks for pointing that out, Dave.  Fixed in latest. How were you running 
(what is in stress.bash?) that caused more issues that "go test -race" 
alone ? 

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Dave Cheney
None whatsoever I'm afraid

On Tuesday, 7 February 2017 16:53:45 UTC+11, Jason E. Aten wrote:
>
>
> On Monday, February 6, 2017 at 11:49:42 PM UTC-6, Dave Cheney wrote:
>
>> The give away is the frequency of the gc lines. gc 15 (the 15th gc event) 
>> happened at 1314 seconds into your programs execution this tells me that gc 
>> is likely not your problem. If it were your terminal would be swamped by gc 
>> log lines indicating the gc was running constantly.
>>
>
> Ok. Any idea was runtime._ExternalCode means? 
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Dave Cheney
I think there are more data races in your product

http://paste.ubuntu.com/23946008/

On Tuesday, 7 February 2017 16:42:28 UTC+11, Jason E. Aten wrote:
>
> the race is fixed in the latest push; 
> a572f570c52f70c9518bc1b3e3319ff9e2424885; it was an artifact of adding 
> logging levels, and would have affected only the tests.
>
> I did manage to catch the processing running away again, this time at 
> 300%, and I got some output with gctrace=1 as you suggested. I'm not sure 
> how to read the lines though; could you advise Dave?
>
>
> runaway cpu behavior happening from at least:
>  Tue Feb  7 05:26:24 UTC 2017  - 2017/02/07 05:37:05.587710
>
> [jaten@host]$ GODEBUG=gctrace=1 go/bin/vhaline.go1.8rc3 -info -addr 
> localhost:9001 -parent localhost:9000 -cpu
> 2017/02/07 05:14:07 mid node 'a7fb658c' started on localhost:9001. my 
> parent is 'localhost:9000'
> 2017/02/07 05:14:07 mid node 'a7fb658c' using ttl=3s and beat=1s.
> 2017/02/07 05:14:07.136012 client.go:85: [pid 86063] replica (a7fb658c) 
> client dialing parent at 'localhost:9000'
> 2017/02/07 05:14:07.136266 client.go:97: [pid 86063] replica (a7fb658c) 
> client reached parent at 'localhost:9000'
> gc 1 @0.007s 1%: 0.18+0.39+0.093 ms clock, 0.36+0.23/0.56/0.23+0.18 ms 
> cpu, 17->17->16 MB, 18 MB goal, 16 P
> gc 2 @0.008s 2%: 0.063+0.43+0.078 ms clock, 0.44+0.033/0.69/0.28+0.55 ms 
> cpu, 32->32->32 MB, 33 MB goal, 16 P
> 2017/02/07 05:14:07.139570 replica.go:511: [pid 86063] replica (a7fb658c) 
> sees from parent: ToChildConnectAck.
> 2017/02/07 05:14:07 pprof profiler providing web server on 'localhost:6061'
> 2017/02/07 05:14:07 cmd/vhaline/main.go: contacted parent event.
> 2017/02/07 05:14:09.139731 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(/).
> 2017/02/07 05:14:09.139759 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000176418s/never
> gc 3 @52.176s 0%: 0.065+0.24+0.082 ms clock, 0.58+0.15/0.62/0.47+0.74 ms 
> cpu, 49->49->48 MB, 65 MB goal, 16 P
> gc 4 @52.177s 0%: 0.041+0.55+0.094 ms clock, 0.502017/02/07 
> 05:14:59.307973 replica.go:742: [pid 86063] replica (a7fb658c) 
> NewChildConnect from child 4040ba06' at '127.0.0.1:46194'
> +0.054/0.54/0.40+1.1 ms cpu, 64->64->64 MB, 97 MB goal, 16 P
> 2017/02/07 05:14:59 cmd/vhaline/main.go: contacted child event.
> 2017/02/07 05:15:16.160638 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:15:16.160673 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000166804s/1.000144038s
> 2017/02/07 05:16:24.182488 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:16:24.182518 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000148515s/1.000133515s
> scvg0: inuse: 68, idle: 0, sys: 69, released: 0, consumed: 69 (MB)
> GC forced
> gc 5 @172.183s 0%: 0.089+0.30+0.086 ms clock, 1.2+0/0.74/1.0+1.2 ms cpu, 
> 67->67->64 MB, 129 MB goal, 16 P
> 2017/02/07 05:17:24.201369 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:17:24.201404 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000158566s/1.000172823s
> 2017/02/07 05:18:29.222380 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:18:29.222413 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000154109s/1.000142059s
> GC forced
> gc 6 @292.191s 0%: 0.18+0.31+0.10 ms clock, 2.7+0/0.72/0.89+1.6 ms cpu, 
> 67->67->64 MB, 129 MB goal, 16 P
> scvg1: inuse: 67, idle: 2, sys: 69, released: 0, consumed: 69 (MB)
> 2017/02/07 05:19:35.243248 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:19:35.243274 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000142593s/1.000160351s
> 2017/02/07 05:20:45.265426 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:20:45.265455 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000176146s/1.000179458s
> GC forced
> gc 7 @412.200s 0%: 0.027+0.28+0.097 ms clock, 0.43+0/0.78/0.69+1.5 ms cpu, 
> 67->67->64 MB, 129 MB goal, 16 P
> scvg2: inuse: 67, idle: 1, sys: 69, released: 0, consumed: 69 (MB)
> 2017/02/07 05:21:54.287241 replica.go:587: [pid 86063] replica (a7fb658c) 
> 

[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Jason E. Aten

On Monday, February 6, 2017 at 11:49:42 PM UTC-6, Dave Cheney wrote:

> The give away is the frequency of the gc lines. gc 15 (the 15th gc event) 
> happened at 1314 seconds into your programs execution this tells me that gc 
> is likely not your problem. If it were your terminal would be swamped by gc 
> log lines indicating the gc was running constantly.
>

Ok. Any idea was runtime._ExternalCode means? 

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Dave Cheney
>  did manage to catch the processing running away again, this time at 
300%, and I got some output with gctrace=1 as you suggested. I'm not sure 
how to read the lines though; could you advise Dave?

The give away is the frequency of the gc lines. gc 15 (the 15th gc event) 
happened at 1314 seconds into your programs execution this tells me that gc 
is likely not your problem. If it were your terminal would be swamped by gc 
log lines indicating the gc was running constantly.

On Tuesday, 7 February 2017 16:42:28 UTC+11, Jason E. Aten wrote:
>
> the race is fixed in the latest push; 
> a572f570c52f70c9518bc1b3e3319ff9e2424885; it was an artifact of adding 
> logging levels, and would have affected only the tests.
>
> I did manage to catch the processing running away again, this time at 
> 300%, and I got some output with gctrace=1 as you suggested. I'm not sure 
> how to read the lines though; could you advise Dave?
>
>
> runaway cpu behavior happening from at least:
>  Tue Feb  7 05:26:24 UTC 2017  - 2017/02/07 05:37:05.587710
>
> [jaten@host]$ GODEBUG=gctrace=1 go/bin/vhaline.go1.8rc3 -info -addr 
> localhost:9001 -parent localhost:9000 -cpu
> 2017/02/07 05:14:07 mid node 'a7fb658c' started on localhost:9001. my 
> parent is 'localhost:9000'
> 2017/02/07 05:14:07 mid node 'a7fb658c' using ttl=3s and beat=1s.
> 2017/02/07 05:14:07.136012 client.go:85: [pid 86063] replica (a7fb658c) 
> client dialing parent at 'localhost:9000'
> 2017/02/07 05:14:07.136266 client.go:97: [pid 86063] replica (a7fb658c) 
> client reached parent at 'localhost:9000'
> gc 1 @0.007s 1%: 0.18+0.39+0.093 ms clock, 0.36+0.23/0.56/0.23+0.18 ms 
> cpu, 17->17->16 MB, 18 MB goal, 16 P
> gc 2 @0.008s 2%: 0.063+0.43+0.078 ms clock, 0.44+0.033/0.69/0.28+0.55 ms 
> cpu, 32->32->32 MB, 33 MB goal, 16 P
> 2017/02/07 05:14:07.139570 replica.go:511: [pid 86063] replica (a7fb658c) 
> sees from parent: ToChildConnectAck.
> 2017/02/07 05:14:07 pprof profiler providing web server on 'localhost:6061'
> 2017/02/07 05:14:07 cmd/vhaline/main.go: contacted parent event.
> 2017/02/07 05:14:09.139731 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(/).
> 2017/02/07 05:14:09.139759 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000176418s/never
> gc 3 @52.176s 0%: 0.065+0.24+0.082 ms clock, 0.58+0.15/0.62/0.47+0.74 ms 
> cpu, 49->49->48 MB, 65 MB goal, 16 P
> gc 4 @52.177s 0%: 0.041+0.55+0.094 ms clock, 0.502017/02/07 
> 05:14:59.307973 replica.go:742: [pid 86063] replica (a7fb658c) 
> NewChildConnect from child 4040ba06' at '127.0.0.1:46194'
> +0.054/0.54/0.40+1.1 ms cpu, 64->64->64 MB, 97 MB goal, 16 P
> 2017/02/07 05:14:59 cmd/vhaline/main.go: contacted child event.
> 2017/02/07 05:15:16.160638 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:15:16.160673 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000166804s/1.000144038s
> 2017/02/07 05:16:24.182488 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:16:24.182518 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000148515s/1.000133515s
> scvg0: inuse: 68, idle: 0, sys: 69, released: 0, consumed: 69 (MB)
> GC forced
> gc 5 @172.183s 0%: 0.089+0.30+0.086 ms clock, 1.2+0/0.74/1.0+1.2 ms cpu, 
> 67->67->64 MB, 129 MB goal, 16 P
> 2017/02/07 05:17:24.201369 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:17:24.201404 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000158566s/1.000172823s
> 2017/02/07 05:18:29.222380 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:18:29.222413 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000154109s/1.000142059s
> GC forced
> gc 6 @292.191s 0%: 0.18+0.31+0.10 ms clock, 2.7+0/0.72/0.89+1.6 ms cpu, 
> 67->67->64 MB, 129 MB goal, 16 P
> scvg1: inuse: 67, idle: 2, sys: 69, released: 0, consumed: 69 (MB)
> 2017/02/07 05:19:35.243248 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 2017/02/07 05:19:35.243274 replica.go:598: [pid 86063] replica (a7fb658c) 
> last-ping (parent/child): 1.000142593s/1.000160351s
> 2017/02/07 05:20:45.265426 replica.go:587: [pid 86063] replica (a7fb658c) 
> line status: parent(bbda6890/localhost:9000) -> me(a7fb658c/localhost:9001) 
> -> child(4040ba06/127.0.0.1:46194).
> 

[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Jason E. Aten
gc 15 @1314.779s 0%: 0.031+0.29+0.11 ms clock, 0.49+0/0.99/0.47+1.7 ms cpu, 
167->167->164 MB, 

wow, does that actually mean a 1314 second garbage collection? holy canoly.

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Dave Cheney
> Since there is nothing that changes in the processes over time, the fact 
that it kicks in after a few minutes makes me think it may be a garbage 
collection issue.   

Running with GODEBUG=gctrace=1 will confirm / deny this hypothesis.

On Tuesday, 7 February 2017 16:06:09 UTC+11, Jason E. Aten wrote:
>
>
> On linux/amd64 using go1.8rc3, I'm seeing one Go built process peg one cpu 
> to 100% after running for a few minutes.
>
>
> Tasks: 499 total,   1 running, 497 sleeping,   0 stopped,   1 
> zombie
>   
>
> %Cpu(s):  2.8 us,  3.5 sy,  0.0 ni, 93.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
> 0.0 
> st
>
>
> KiB Mem : 12356040+total, 65169064 free,  5018704 used, 53372628 
> buff/cache
>
>
> KiB Swap:0 total,0 free,0 used. 11790566+avail 
> Mem   
>  
>
>   
>   
>   
>
>   PID USER  PR  NIVIRTRESSHR S  %CPU %MEM TIME+ 
> COMMAND   
> 
>
>   84359 jaten 20   0 1156916  52152   4632 S 100.7  0.0   9:05.82 
> vhaline -info -web -addr 
> loc+  
>  
>
>   84486 jaten 20   0  941964  19884   4268 S   0.7  0.0   0:05.58 
> vhaline -info -addr 
> localhos+ 
>   
>
>   84501 jaten 20   0 1020484  14712   4216 S   0.7  0.0   0:04.95 
> vhaline -info -addr localhos+   
>
>
> when I profile, I get alot fo runtime._ExternalCode. What is that and what 
> does it mean?
>
> $ go tool pprof --nodefraction=0.1 vhaline 
> ./profile.cpu.runaway.rootnode   
> Entering interactive mode (type "help" for 
> commands) 
>  
>
> (pprof) 
> top10 
> 
>
> 21.16s of 29.97s total 
> (70.60%)  
>  
>
> Dropped 55 nodes (cum <= 
> 3s)   
>
>
> Showing top 10 nodes out of 16 (cum >= 
> 10.61s)   
>  
>
>   flat  flat%   sum%cum   
> cum%  
>   
>
> 13.55s 45.21% 45.21% 13.55s 45.21%  
> runtime._ExternalCode 
> 
>
>  6.23s 20.79% 66.00%  7.85s 26.19%  
> syscall.Syscall   
> 
>
>  0.27s   0.9% 66.90% 16.42s 54.79%  
> github.com/glycerine/vhaline/vhaline.(*srvReader).start.func1 
> 
>
>  0.25s  0.83% 67.73% 10.20s 34.03%  
> net.(*netFD).Read 
> 
>
>  0.23s  0.77% 68.50%  3.96s 13.21%  
> net.setDeadlineImpl   
> 
>
>  0.20s  0.67% 69.17% 10.96s 36.57%  
> bufio.(*Reader).Peek  
> 
>
>  0.12s   0.4% 69.57% 10.76s 35.90%  
> bufio.(*Reader).fill  
> 
>
>  0.11s  0.37% 69.94% 11.09s 37.00%  
> github.com/glycerine/tmframe2.(*FrameReader).NextFrame
> 
>
>  0.11s  0.37% 70.30%  7.96s 26.56%  
> syscall.read  
> 
>
>  0.09s   0.3% 70.60% 10.61s 35.40%  
> net.(*conn).Read  
> 
>
> (pprof)  
>
> source code is here; the processes can be built from 
> https://github.com/glycerine/vhaline  at commit commit 
> ca32a98799b87627798e05bb8e6cc29d9cac7ec3 or using tag "runaway".
>
> pprof profiling was turned on; could this account for this peg?
>
> I was running three vhaline processes in a chain; the cpu peg 

[go-nuts] Re: Does my gofmt work wrongly or I don't understand something ?

2017-02-06 Thread fsn761304


On Monday, February 6, 2017 at 2:39:04 AM UTC+4, howar...@gmail.com wrote:
>
> What were you expecting to happen?
>
> The documentation says: 
>
>Both  pattern and replacement must be valid Go expressions. In the 
> pat‐
>tern, single-character lowercase identifiers serve as wildcards 
>  match‐
>ing  arbitrary  sub-expressions;  those expressions will be 
> substituted
>for the same identifiers in the replacement.
>
> So if 'h' had shown up in the replacement, it would get replaced with the 
> original identifier - but it did not appear, instead H did.
>
> It *looks* like you were expecting it to change the "hello, world\n" to 
> "Hello, world\n"? But gofmt's -r requires that both pattern and replacement 
> be valid Go expressions. 
>
> This:
> gofmt -r "\"hello, world\\n\" -> \"Hello, world\\n\""
>
> Has the effect I think you might have been going for. I'm not certain what 
> you were intending though, so I'm not sure of that.
>
> That's it, than you very much. 

-- 
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 https://groups.google.com/d/optout.


[go-nuts] troubleshooting 100% cpu peg - runtime._ExternalCode ?

2017-02-06 Thread Jason E. Aten

On linux/amd64 using go1.8rc3, I'm seeing one Go built process peg one cpu 
to 100% after running for a few minutes.


Tasks: 499 total,   1 running, 497 sleeping,   0 stopped,   1 
zombie  


%Cpu(s):  2.8 us,  3.5 sy,  0.0 ni, 93.7 id,  0.0 wa,  0.0 hi,  0.0 si,  
0.0 
st  
 

KiB Mem : 12356040+total, 65169064 free,  5018704 used, 53372628 
buff/cache  
 

KiB Swap:0 total,0 free,0 used. 11790566+avail 
Mem 
   



  

  PID USER  PR  NIVIRTRESSHR S  %CPU %MEM TIME+ 
COMMAND 
  

  84359 jaten 20   0 1156916  52152   4632 S 100.7  0.0   9:05.82 
vhaline -info -web -addr 
loc+
   

  84486 jaten 20   0  941964  19884   4268 S   0.7  0.0   0:05.58 
vhaline -info -addr 
localhos+   


  84501 jaten 20   0 1020484  14712   4216 S   0.7  0.0   0:04.95 
vhaline -info -addr localhos+   


when I profile, I get alot fo runtime._ExternalCode. What is that and what 
does it mean?

$ go tool pprof --nodefraction=0.1 vhaline 
./profile.cpu.runaway.rootnode   
Entering interactive mode (type "help" for 
commands)   
   

(pprof) 
top10   
  

21.16s of 29.97s total 
(70.60%)
   

Dropped 55 nodes (cum <= 
3s) 
 

Showing top 10 nodes out of 16 (cum >= 
10.61s) 
   

  flat  flat%   sum%cum   
cum%


13.55s 45.21% 45.21% 13.55s 45.21%  
runtime._ExternalCode   
  

 6.23s 20.79% 66.00%  7.85s 26.19%  
syscall.Syscall 
  

 0.27s   0.9% 66.90% 16.42s 54.79%  
github.com/glycerine/vhaline/vhaline.(*srvReader).start.func1   
  

 0.25s  0.83% 67.73% 10.20s 34.03%  
net.(*netFD).Read   
  

 0.23s  0.77% 68.50%  3.96s 13.21%  
net.setDeadlineImpl 
  

 0.20s  0.67% 69.17% 10.96s 36.57%  
bufio.(*Reader).Peek
  

 0.12s   0.4% 69.57% 10.76s 35.90%  
bufio.(*Reader).fill
  

 0.11s  0.37% 69.94% 11.09s 37.00%  
github.com/glycerine/tmframe2.(*FrameReader).NextFrame  
  

 0.11s  0.37% 70.30%  7.96s 26.56%  
syscall.read
  

 0.09s   0.3% 70.60% 10.61s 35.40%  
net.(*conn).Read
  

(pprof)  

source code is here; the processes can be built from 
https://github.com/glycerine/vhaline  at commit commit 
ca32a98799b87627798e05bb8e6cc29d9cac7ec3 or using tag "runaway".

pprof profiling was turned on; could this account for this peg?

I was running three vhaline processes in a chain; the cpu peg happened to 
the first process, but I've also seen it happen for the 2nd.

they were started like this, in three separate shells
$ vhaline -info -web -addr localhost:9000  # 
process 84359
$ vhaline -info -addr localhost:9001 -parent localhost:9000 -cpu   # 
process 84486
$ vhaline -info -addr localhost:9002 -parent localhost:9001 -cpu   # 
process 84501

Since there is nothing that changes in the processes over time, the fact 
that it kicks in after a few minutes makes me think it may be a 

[go-nuts] Re: Using React with Golang? and does it make sense?

2017-02-06 Thread Kevin Powick

On Monday, 6 February 2017 23:37:15 UTC-5, so.q...@gmail.com wrote:
>
>
> You said that Node is not required. But I thought react components are 
> actually JavaScript objects.
>

They are.  They execute on the client side, in the web browser.

 

> Would my Golang API server be responding back to requests with those 
> JavaScript objects for the React library to render on the client's browser?
>


Your Go API service would be responding with data (presumably from a 
database), formatted as JSON.  The data would have been requested by the 
React objects executing in the client browser.

*Example*

Suppose you have a Go service that returns details about a customer for a 
given a customer ID.  The endpoint might be an HTTP GET request that looks 
like the following

http://myService/customer/123456

The details are returned in JSON format

{"Id":123456,"Name":"Bob Smith","Age":25}


On the client side, you would have used JavaScript/React to make the API 
Call (HTTP GET) and populate your React object with the returned data, 
which would then be rendered in your browser UI (page).

The advantage of your Go service simply returning JSON data is that it can 
be consumed by any client software capable of an HTTP request.  This make 
it available to any number of languages with HTTP Client libraries 
available.  These days, that's pretty much any language you would care to 
work with.  

--
Kevin Powick

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Using React with Golang? and does it make sense?

2017-02-06 Thread mark
A little over a year ago, I experimented with server-side React rendering 
in Go [1] via otto [2].

At least back then, otto wasn't fully ECMA5-compliant due to not supporting 
negative lookaheads in regular expressions;
I had to open a PR on React [3] to remove one negative lookahead in the 
render path.

I have no idea if otto can run the current version of React, and it's been 
so long since I've tried using otto with React that I won't be able to 
answer any questions about that setup.
Hopefully this was still useful information.

[1] https://github.com/mark-rushakoff/go-reactjs-benchmarks
[2] https://github.com/robertkrimen/otto
[3] https://github.com/facebook/react/pull/5614

On Monday, February 6, 2017 at 9:09:10 AM UTC-8, so.q...@gmail.com wrote:
>
> Correct me if I'm wrong, but in serving web apps and sites.
>
> Golang simply fills in the blanks for predefined templates.
>
> React appears to be a bit more complicated requiring the creation of 
> JavaScript/JSX classes representing the view. Having that rendered on the 
> server-side and the difference applied on the client.
>
> To combine the two, do I need to run Node.js on the server to process the 
> React/JSX classes before piping the results to Golang for responding to the 
> client? So Golang would be the conduit/middle-man filling in for Express 
> here.
>
> Does this even make sense? If I'm already running Node.js, does the use of 
> Golang feel superfluous?
>
>
>
>
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: GUI for simple cross-platform Go app

2017-02-06 Thread Tong Sun

On Monday, February 6, 2017 at 5:51:28 PM UTC-5, Guber nator wrote:
>
> Hello,
>
> I have started to work on a project where I will need to build a simple 
> cross platform GUI app in Go that will display transparent image on the 
> desktop (like this one: 
> https://upload.wikimedia.org/wikipedia/commons/2/23/Golang.png - 
>  transparent background) always on top, no window decorations. 
> I have never built anything like this and I found couple of libraries for 
> that:
> https://go.libhunt.com/categories/494-gui  (have tested few)
>
> Maybe anyone could suggest which library might be better for this type of 
> work and maybe any examples?
>

I'm not expert on this and I've tried none of the GUI libs, however, I'm 
interested in the topic and have been watching closely over its progress. 

If I'm to pick one today, I'd go for

*Platform-native GUI library for Go*
https://github.com/andlabs/ui

instead of QT. 

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Using React with Golang? and does it make sense?

2017-02-06 Thread so . query
Thanks for the comment.

You said that Node is not required. But I thought react components are 
actually JavaScript objects. Would my Golang API server be responding back 
to requests with those JavaScript objects for the React library to render 
on the client's browser?




On Monday, February 6, 2017 at 4:29:43 PM UTC-8, Kevin Powick wrote:
>
> React is one of many client side (browser) JavaScript frameworks for 
> building user interfaces.
>
> JSX is not required when using React, but is recommended as it gives you 
> the full power of JavaScript to describe your rendered HTML.
>
> Node is not required.  If you're using Go, use it to build a server-side 
> JSON API and, optionally, act as your web server.
>
> Our last project was a Go based API service with the HTML/JS/CCS served-up 
> by Caddy (a web server written in Go).  On the client side we used VueJS, 
> one of the bazillion alternatives to React.
>
> It's all works quite well, and I would recommend a similar approach for 
> those looking to use a Go based solution.  i.e. Go JSON API services with 
> your web server and JS framework of choice.
>
> --
> Kevin Powick
>
> On Monday, 6 February 2017 12:09:10 UTC-5, so.q...@gmail.com wrote:
>>
>> Correct me if I'm wrong, but in serving web apps and sites.
>>
>> Golang simply fills in the blanks for predefined templates.
>>
>> React appears to be a bit more complicated requiring the creation of 
>> JavaScript/JSX classes representing the view. Having that rendered on the 
>> server-side and the difference applied on the client.
>>
>> To combine the two, do I need to run Node.js on the server to process the 
>> React/JSX classes before piping the results to Golang for responding to the 
>> client? So Golang would be the conduit/middle-man filling in for Express 
>> here.
>>
>> Does this even make sense? If I'm already running Node.js, does the use 
>> of Golang feel superfluous?
>>
>>
>>
>>
>>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Migrating from a classic OO pattern

2017-02-06 Thread Tong Sun


On Wednesday, February 1, 2017 at 12:56:19 PM UTC-5, jul.s...@gmail.com 
wrote:
>
> ...
> I'm far from having perfect understanding on the language but I'm starting 
> to get the differences with a «typical» OO language and how to leverage its 
> strengths
>
> I'd have to say this one: https://play.golang.org/p/QQvWxfOiMB seems 
> interesting even though its a tiny bit more complex to understand so I'll 
> definitely look into that little pattern with base/derived
>

Not long ago, there is a similar discussion, 

Thinking OO virtual function in Go
https://groups.google.com/forum/?hl=en#!searchin/golang-nuts/OO$20|sort:relevance/golang-nuts/f_62HEOIBV4/1XjsV72VBwAJ

Many advice in there are much more easier to understand. 

The useful demos are collected as *Polymorphism-Animal.go* & 
*Polymorphism-AnimalV1*~*3*.go under 
https://github.com/suntong/lang/blob/master/lang/Go/src/oo/
with my pick 
being 
https://github.com/suntong/lang/blob/master/lang/Go/src/oo/Polymorphism-AnimalVF3.go

HTH






-- 
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 https://groups.google.com/d/optout.


[go-nuts] storing transaction in context

2017-02-06 Thread Dave Cheney
I'd say store that context in your transaction value, not the other way around. 

-- 
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 https://groups.google.com/d/optout.


RE: [go-nuts] 17.3 trace.exe malware flag on win32

2017-02-06 Thread John Souvestre
I don’t see any problem when I scan it with BitDefender.  I’m running the 
Internet Security 2016 version, build 20.0.29.1550.  How about you?

 

John

John Souvestre - New Orleans LA

 

From: golang-nuts@googlegroups.com [mailto:golang-nuts@googlegroups.com] On 
Behalf Of xiiop...@gmail.com
Sent: 2017 February 06, Mon 19:52
To: golang-nuts
Subject: [go-nuts] 17.3 trace.exe malware flag on win32

 

Not sure if this is known but I seem to be getting a malware flag on 

 

go/pkg/tool/windows_386/trace.exe ie  https://golang.org/pkg/runtime/trace/

 

of Trojan:Win32/Skeeyah.A!rfn ie 
https://www.microsoft.com/security/portal/threat/encyclopedia/entry.aspx?name=Trojan%3aWin32%2fSkeeyah.A!rfn

 

when scanned with windows defender.

 

 

At first I though I had screwed up because I had installed a few programs 
recently (maybe I still have..) - but I re-downoaded 1.73 and it detected it 
again on unzipping

 

No issues on 17.5, assuming a false positive on 1.73

 

It's definitely coming from https://golang.org/dl/ - the download url 
https://storage.googleapis.com/golang/go1.7.3.windows-386.zip

 

 

Can someone double check thanks.

-- 
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 https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] ssh login failed

2017-02-06 Thread Brad Fitzpatrick
Maybe Han-Wen, copied, knows.


On Mon, Feb 6, 2017 at 7:00 PM, Robert Hsiung  wrote:

> Hi Brad:
> Thanks so much for your suggestion. I run "ssh -v" and get useful
> information as attachment.So,I modify the code,but occurred the different
> problem as below.
> ssh: handshake failed: ssh: unexpected message type 3 (expected one of [6])
>
> // ftp
>
> package main
>
>
> import (
>
> "fmt"
>
>
> "github.com/pkg/sftp"
>
> "golang.org/x/crypto/ssh"
>
> )
>
>
> func main() {
>
> c := {
>
> User: "root",
>
> Auth: []ssh.AuthMethod{
>
> ssh.Password("12345678"),
>
> },
>
> }
>
> connection, err := ssh.Dial("tcp", "192.168.44.129:22", c) // replace this
>
> if err != nil {
>
> fmt.Println(err)
>
> return
>
> }
>
>
> server, err := sftp.NewClient(connection)
>
> if err != nil {
>
> fmt.Println(err)
>
> return
>
> }
>
>
> dir, err := server.ReadDir(".")
>
> if err != nil {
>
> fmt.Println(err)
>
> return
>
> }
>
> for _, fi := range dir {
>
> fmt.Println(fi.Name())
>
> }
>
> }
>
>
> 2017-02-07 0:55 GMT+08:00 Brad Fitzpatrick :
>
>> From looking at:
>>
>> ssh: unable to authenticate, attempted methods [none], no supported
>> methods remain
>>
>> It seems like your ssh server requires a different authentication mode
>> and doesn't support KeyboardInteractive (a password).
>>
>> Does the standard ssh client work? What does "ssh -v" say?
>>
>>
>> On Mon, Feb 6, 2017 at 1:25 AM, Robert Hsiung 
>> wrote:
>>
>>> Dear all:
>>> I tried to test sftp function with below coding,but occurred problem as
>>> below. Please give me suggestions. Thanks so much.
>>> ssh: handshake failed: ssh: unable to authenticate, attempted methods
>>> [none], no supported methods remain
>>>
>>> 
>>> package main
>>>
>>> import (
>>> "fmt"
>>> "github.com/pkg/sftp"
>>> "golang.org/x/crypto/ssh"
>>> )
>>>
>>> func main() {
>>>
>>> c := {
>>> User: "root", // replace this
>>> Auth: []ssh.AuthMethod{
>>> ssh.KeyboardInteractive(func(user, instruction string, questions
>>> []string, echos []bool) ([]string, error) {
>>> // Just send the password back for all questions
>>> answers := make([]string, len(questions))
>>> for i, _ := range answers {
>>> answers[i] = "12345678" // replace this
>>> }
>>>
>>> return answers, nil
>>> }),
>>> },
>>> }
>>>
>>> connection, err := ssh.Dial("tcp", "192.168.0.1:22", c) // replace this
>>> if err != nil {
>>> fmt.Println(err)
>>> return
>>> }
>>>
>>> server, err := sftp.NewClient(connection)
>>> if err != nil {
>>> fmt.Println(err)
>>> return
>>> }
>>>
>>> dir, err := server.ReadDir(".")
>>> if err != nil {
>>> fmt.Println(err)
>>> return
>>> }
>>>
>>> for _, fi := range dir {
>>> fmt.Println(fi.Name())
>>> }
>>> }
>>>
>>> --
>>> 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 https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Is there something wrong with performance of select in a for loop

2017-02-06 Thread fwang2002
I know the compare to nodejs doesn't mean anything because of different 
mechanism.

I just want to find out what is the best way to use select, specially in a 
for loop.

And in my messageLoop case, perhaps I have to reduce the number of channels 
in the select, and make multiple kind of events route to only one channel.


在 2017年2月6日星期一 UTC+8上午3:00:15,fwan...@gmail.com写道:
>
> I make a test to see the performance of select, and found the result is 
> not good.
>
> I make 1000 SeqQueue objects and run its messageLoop function (which does 
> a small piece of work, and is listed as below) in 1000 separate go 
> routines. The CPU cost is more than 20%.
> If I make the ticker 1 second, the CPU cost can slow down to about 2%.
>
> With pprof, I see the most top cost are methods related to 
> runtime.selectGo, runtime.lock.
>
> Who knows is there anything wrong in my case?
>
> func (this *SeqQueue) messageLoop() {
> var ticker = time.NewTicker(100 * time.Millisecond)
> defer ticker.Stop()
> for {
> select {
> case <-serverDone:
> return
> case <-this.done:
> return
> case <-ticker.C:
> this.tickCounter += 1
> case message := <-this.messages:
> this.messageCounter += 1
> _ = message
> }
> }
> }
>
>
>
>

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] ssh login failed

2017-02-06 Thread Robert Hsiung
Hi Brad:
Thanks so much for your suggestion. I run "ssh -v" and get useful
information as attachment.So,I modify the code,but occurred the different
problem as below.
ssh: handshake failed: ssh: unexpected message type 3 (expected one of [6])

// ftp

package main


import (

"fmt"


"github.com/pkg/sftp"

"golang.org/x/crypto/ssh"

)


func main() {

c := {

User: "root",

Auth: []ssh.AuthMethod{

ssh.Password("12345678"),

},

}

connection, err := ssh.Dial("tcp", "192.168.44.129:22", c) // replace this

if err != nil {

fmt.Println(err)

return

}


server, err := sftp.NewClient(connection)

if err != nil {

fmt.Println(err)

return

}


dir, err := server.ReadDir(".")

if err != nil {

fmt.Println(err)

return

}

for _, fi := range dir {

fmt.Println(fi.Name())

}

}


2017-02-07 0:55 GMT+08:00 Brad Fitzpatrick :

> From looking at:
>
> ssh: unable to authenticate, attempted methods [none], no supported
> methods remain
>
> It seems like your ssh server requires a different authentication mode and
> doesn't support KeyboardInteractive (a password).
>
> Does the standard ssh client work? What does "ssh -v" say?
>
>
> On Mon, Feb 6, 2017 at 1:25 AM, Robert Hsiung  wrote:
>
>> Dear all:
>> I tried to test sftp function with below coding,but occurred problem as
>> below. Please give me suggestions. Thanks so much.
>> ssh: handshake failed: ssh: unable to authenticate, attempted methods
>> [none], no supported methods remain
>>
>> 
>> package main
>>
>> import (
>> "fmt"
>> "github.com/pkg/sftp"
>> "golang.org/x/crypto/ssh"
>> )
>>
>> func main() {
>>
>> c := {
>> User: "root", // replace this
>> Auth: []ssh.AuthMethod{
>> ssh.KeyboardInteractive(func(user, instruction string, questions
>> []string, echos []bool) ([]string, error) {
>> // Just send the password back for all questions
>> answers := make([]string, len(questions))
>> for i, _ := range answers {
>> answers[i] = "12345678" // replace this
>> }
>>
>> return answers, nil
>> }),
>> },
>> }
>>
>> connection, err := ssh.Dial("tcp", "192.168.0.1:22", c) // replace this
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>>
>> server, err := sftp.NewClient(connection)
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>>
>> dir, err := server.ReadDir(".")
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>>
>> for _, fi := range dir {
>> fmt.Println(fi.Name())
>> }
>> }
>>
>> --
>> 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 https://groups.google.com/d/optout.
>>
>
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] storing transaction in context

2017-02-06 Thread Steven Roth
I'd like input on whether the following idea is good or bad, and why.

Consider an abstract transaction, modeled as follows:
func Transaction(ctx context.Context, body func(ctx context.Context) error)
error
func OnCommit(ctx context.Context, commitHook func(ctx context.Context))
func OnRollback(ctx context.Context, rollbackHook func(ctx context.Context))

The code that wishes to execute a transaction would call Transaction and
provide the body of the transaction as a function parameter.  If that
function returns an error, the transaction is rolled back, by calling any
hooks registered during that transaction by calling OnRollback.  If the
body function returns success, the transaction is committed by calling any
hooks registered during that transaction by calling OnCommit.

The implication of this model is that the identity of what transaction
you're in is stored in the context.  The ctx passed into body has that
value added to it, and the OnCommit and OnRollback calls associate the
hooks with the transaction they find in the context.

Of course the same thing could be done by passing the transaction
explicitly, e.g.
func Transaction(ctx context.Context, body func(ctx context.Context, tx Tx)
error) error
func OnCommit(tx Tx, commitHook func(ctx context.Context))
func OnRollback(tx Tx, rollbackHook func(ctx context.Context))

But this would mean that both ctx and tx would have to be passed in
parameters to all functions called during the body of the transaction.  My
question is whether putting the transaction in the context using
context.WithValue is a reasonable and appropriate use of that mechanism.
If not, why not?

The use case for this transaction model is not really relevant to the
question, but I'll include it for illustrative purposes.  Imagine a web
server implemented in layers, e.g. transport on top of service on top of
database access.  One would like to promote the transaction concept out of
the database access layer so that multiple calls from the service layer to
the database access layer could occur within the same database
transaction.  One way to do that would be to wrap the service call in an
abstract transaction, and have the database layer honor that with database
transactions in an encapsulated fashion.

Many thanks in advance for your reactions and wisdom.
Steve

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: GUI for simple cross-platform Go app

2017-02-06 Thread Fino
I think there is no GUI lib in Golang can do software for serious business.

if it is not for play,  use QT or others is better for business 
decision. 

BR fino

在 2017年2月7日星期二 UTC+8上午6:51:28,Guber nator写道:
>
> Hello,
>
> I have started to work on a project where I will need to build a simple 
> cross platform GUI app in Go that will display transparent image on the 
> desktop (like this one: 
> https://upload.wikimedia.org/wikipedia/commons/2/23/Golang.png - 
>  transparent background) always on top, no window decorations. 
> I have never built anything like this and I found couple of libraries for 
> that:
> https://go.libhunt.com/categories/494-gui  (have tested few)
>
> Maybe anyone could suggest which library might be better for this type of 
> work and maybe any examples?
>
> Many thanks!
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: json: cannot unmarshal array into Go value of type main error

2017-02-06 Thread Kevin Powick

Since you have an array of JSON data, you need to Unmarshal it into an 
Array of your struct, then range over the resulting array of your struct.

Updated version of your code at: https://play.golang.org/p/gnx7pjTzOT

--
Kevin Powick

On Thursday, 2 February 2017 18:20:49 UTC-5, Rejoy wrote:
>
>
> I 'd like to unmarshal database records into a struct type. I get the 
> error "json: cannot unmarshal array into Go value of type main..".
>
> Working example https://play.golang.org/p/keY-3z7lyA
>  
> I can unmarshal the data to []map[String]string, but cannot reference it 
> using key value pairs in the template.
>
> The snippet for code in the template:
>  
>  {{ range $key, $value := . }} 
> {{ $key }}: {{ $value }} 
> {{ end }} 
> 
>
> The output that I get on the webserver:
>
> - *0*: map[quantity:100 image:1Appleiphone7.jpeg pname:iphone7 
> price:7 puid:d6742e4e-2ad6-43c5-97f4-e8a7b00684e2] 
> - *1*: map[image:2SamsungGalaxys7.jpeg pname:SamsungGalaxy7 price:7 
> puid:12d3d8fc-66b6-45f9-a91b-d400b91c32aa quantity:100]
>
>
>
> I wanted to display the data as a table by ranging over the key-value 
> pairs. But am not able to figure out how.
>
>
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Go Fonts: request for feedback

2017-02-06 Thread Kevin Powick
Not being familiar with the field of typography, I have no idea how these 
changes will affect the Go fonts.

However, if they make the examples shown in the Go blog from November 2016 
significantly less ugly, I'm all for ti.

--
Kevin Powick

On Thursday, 2 February 2017 19:25:42 UTC-5, Nigel Tao wrote:
>
> Bigelow & Holmes, the designers of the Go Fonts, are preparing an 
> update to those fonts. The changes so far are: 
>
> • adjusted box/chart/shade/split-integral to align vertically 
> • adjusted shade characters to align vertically & horizontally (more 
> or less aesthetically) 
> • merged the contours of ring of Aring U+00C5 with the A 
> • renamed U+02C9 -> uni02C9 in Bold and Bold Italic to conform to name 
> in Regular and Italic and avoid name conflict with "macron" 
> • added U+FFFD "Replacement" character 
>
> If you have any other bug reports, feature requests, or just like to 
> comment in general, please reply to the discussion group here, and 
> I'll pass it on to B 
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Using React with Golang? and does it make sense?

2017-02-06 Thread ivan
You don't have to use server-side rendering. You can have the React client 
make ajax requests to your Go backend.

On Monday, February 6, 2017 at 12:09:10 PM UTC-5, so.q...@gmail.com wrote:
>
> Correct me if I'm wrong, but in serving web apps and sites.
>
> Golang simply fills in the blanks for predefined templates.
>
> React appears to be a bit more complicated requiring the creation of 
> JavaScript/JSX classes representing the view. Having that rendered on the 
> server-side and the difference applied on the client.
>
> To combine the two, do I need to run Node.js on the server to process the 
> React/JSX classes before piping the results to Golang for responding to the 
> client? So Golang would be the conduit/middle-man filling in for Express 
> here.
>
> Does this even make sense? If I'm already running Node.js, does the use of 
> Golang feel superfluous?
>
>
>
>
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] GUI for simple cross-platform Go app

2017-02-06 Thread Guber nator
Hello,

I have started to work on a project where I will need to build a simple 
cross platform GUI app in Go that will display transparent image on the 
desktop (like this one: 
https://upload.wikimedia.org/wikipedia/commons/2/23/Golang.png - 
 transparent background) always on top, no window decorations. 
I have never built anything like this and I found couple of libraries for 
that:
https://go.libhunt.com/categories/494-gui  (have tested few)

Maybe anyone could suggest which library might be better for this type of 
work and maybe any examples?

Many thanks!

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] Go vet context leak error

2017-02-06 Thread Sameer Ajmani
Perhaps just read the deadline in the lock, then do the rest outside the
lock:

func (s *SimplePeerConn) Read(b []byte) (n int, err error) {
  s.deadlineLock.RLock()
  deadline := s.readDeadline
  s.deadlineLock.RUnlock()

  ctx := context.Background()
  if !deadline.IsZero() {
dctx, cancel := context.WithDeadline(ctx, deadline)
defer cancel()
ctx = dctx
  }
  return s.ReadWithContext(ctx, b)
}

On Mon, Feb 6, 2017 at 4:34 PM  wrote:

> I have the following function:
>
> func (s *SimplePeerConn) Read(b []byte) (n int, err error) {
>   ctx := context.Background()
>   var maybeCancelFn context.CancelFunc
>   func() {
> s.deadlineLock.RLock()
> defer s.deadlineLock.RUnlock()
> if !s.readDeadline.IsZero() {
>   ctx, maybeCancelFn = context.WithDeadline(ctx, s.readDeadline)
> }
>   }()
>   if maybeCancelFn != nil {
> defer maybeCancelFn()
>   }
>   return s.ReadWithContext(ctx, b)
> }
>
> And I'm getting a possible context leak when I assign maybeCancelFn. I
> originally had context.WithCancel and then overwrote the cancelFn in the
> inner func.
> How would I idiomatically rewrite this to not see the vet error?
>
> --
> 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 https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Go vet context leak error

2017-02-06 Thread chad . retz
I have the following function:

func (s *SimplePeerConn) Read(b []byte) (n int, err error) {
  ctx := context.Background()
  var maybeCancelFn context.CancelFunc
  func() {
s.deadlineLock.RLock()
defer s.deadlineLock.RUnlock()
if !s.readDeadline.IsZero() {
  ctx, maybeCancelFn = context.WithDeadline(ctx, s.readDeadline)
}
  }()
  if maybeCancelFn != nil {
defer maybeCancelFn()
  }
  return s.ReadWithContext(ctx, b)
}

And I'm getting a possible context leak when I assign maybeCancelFn. I 
originally had context.WithCancel and then overwrote the cancelFn in the 
inner func. 
How would I idiomatically rewrite this to not see the vet error?

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Hidden vendoring trap

2017-02-06 Thread Tamás Gulácsi
I've fallen into a quite hideous trap:
after upgrading google.golang.org/grpc, my app compiled, but paniced with 
double "/debug/requests" handle registration in net/http.

This is caused by double import of golang.org/x/net/trace, two different 
versions: one is in google.golang.org/grpc, the other is a mystery...

With the help of `go list -f {{.Deps}}` I've found that camlistore.org 
vendored golang.org/x/net/trace!
This is reasonable, as Camlistore is a huge application, but I've just 
imported parts of it (camlistore.org/pkg/client).

Why is the src/camlistore.org/vendor directory used when importing from 
camlistore.org/pkg/client ? (Go 1.8rc3)
AFAIK the idiomatic way is to NOT vendor in libraries, only in the 
application - Camlistore is both, at the moment...

What's your suggestion?
Shall we reorganize camlistore.org? (move vendor/ under 
camlistore.org/cmd/vendor?)
Shall we modify go building to ignore vendor under subtrees (non-main 
packages)?

Thanks,
Tamás Gulácsi

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] Problems drawing on frames of an animated gif

2017-02-06 Thread gary . willoughby
Thanks!

On Sunday, 5 February 2017 01:25:21 UTC, Nigel Tao wrote:
>
> On Mon, Jan 23, 2017 at 6:03 AM, kalekold via golang-nuts 
>  wrote: 
> > Hmm.. the source gif I'm using must be compressed. Doesn't Go handle 
> > compressed gifs in the same way? When you say 'I may get unexpected 
> results' 
> > is that because the current gif package doesn't support compression? 
>
> A GIF image is a sequence of frames. Some frames are complete 
> pictures, some frames contain only those pixels that changed from the 
> previous frame. (If you're familiar with video formats like MPEG, you 
> might recognize these concepts as I-frames and P-frames). 
>
> The second type of frame, delta frames or P-frames, often encode much 
> smaller since they're often mostly transparent, and so are sometimes 
> called "compressed" GIFs. Both sorts of frames also use LZW 
> compression, but that's probably not what we're discussing here. 
>
> The Go image/gif package supports complete and delta frames. As per 
> the GIF spec (http://www.w3.org/Graphics/GIF/spec-gif89a.txt), the 
> package calls this the disposal method. Support means that decoding a 
> GIF image will give you the per-frame disposal methods, and passing a 
> slice of per-frame disposal methods to Encode will produce a well 
> formatted GIF. 
>
> However, the package does not apply the deltas to previous frames for 
> you. If you want to load an animated GIFs and replace some frames, it 
> is up to the user of the image/gif package (i.e. you) to apply the 
> deltas when decoding, or re-calculate the deltas when encoding. Or you 
> can set decoded.Disposal[i] to gif.DisposalNone to change the frame 
> from a P-frame to an I-frame, but that might lead to a larger GIF 
> file. 
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Using React with Golang? and does it make sense?

2017-02-06 Thread so . query
Correct me if I'm wrong, but in serving web apps and sites.

Golang simply fills in the blanks for predefined templates.

React appears to be a bit more complicated requiring the creation of 
JavaScript/JSX classes representing the view. Having that rendered on the 
server-side and the difference applied on the client.

To combine the two, do I need to run Node.js on the server to process the 
React/JSX classes before piping the results to Golang for responding to the 
client? So Golang would be the conduit/middle-man filling in for Express 
here.

Does this even make sense? If I'm already running Node.js, does the use of 
Golang feel superfluous?




-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] ssh login failed

2017-02-06 Thread Brad Fitzpatrick
>From looking at:

ssh: unable to authenticate, attempted methods [none], no supported methods
remain

It seems like your ssh server requires a different authentication mode and
doesn't support KeyboardInteractive (a password).

Does the standard ssh client work? What does "ssh -v" say?


On Mon, Feb 6, 2017 at 1:25 AM, Robert Hsiung  wrote:

> Dear all:
> I tried to test sftp function with below coding,but occurred problem as
> below. Please give me suggestions. Thanks so much.
> ssh: handshake failed: ssh: unable to authenticate, attempted methods
> [none], no supported methods remain
>
> 
> package main
>
> import (
> "fmt"
> "github.com/pkg/sftp"
> "golang.org/x/crypto/ssh"
> )
>
> func main() {
>
> c := {
> User: "root", // replace this
> Auth: []ssh.AuthMethod{
> ssh.KeyboardInteractive(func(user, instruction string, questions
> []string, echos []bool) ([]string, error) {
> // Just send the password back for all questions
> answers := make([]string, len(questions))
> for i, _ := range answers {
> answers[i] = "12345678" // replace this
> }
>
> return answers, nil
> }),
> },
> }
>
> connection, err := ssh.Dial("tcp", "192.168.0.1:22", c) // replace this
> if err != nil {
> fmt.Println(err)
> return
> }
>
> server, err := sftp.NewClient(connection)
> if err != nil {
> fmt.Println(err)
> return
> }
>
> dir, err := server.ReadDir(".")
> if err != nil {
> fmt.Println(err)
> return
> }
>
> for _, fi := range dir {
> fmt.Println(fi.Name())
> }
> }
>
> --
> 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 https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] How to idiomatically display chained errors?

2017-02-06 Thread so . query
That does look better.

Are there any other examples from the Go source I can look at it?



On Sunday, February 5, 2017 at 1:56:51 PM UTC-8, Lars Seipel wrote:
>
> On Sat, Feb 04, 2017 at 12:08:20AM -0800, so.q...@gmail.com  
> wrote: 
> > The following would print out "ERROR: Foo() ERROR: Bar() ERROR: 
> > stdlib.Func() something went wrong with this standard function call", 
> which 
> > feels obviously wrong. 
>
> Leave out the "ERROR" string as well as the gratuitous parens and you 
> get something like "foo: bar: open: file does not exist" which looks 
> almost reasonable. 
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] ssh login failed

2017-02-06 Thread Robert Hsiung
Dear all:
I tried to test sftp function with below coding,but occurred problem as 
below. Please give me suggestions. Thanks so much.
ssh: handshake failed: ssh: unable to authenticate, attempted methods 
[none], no supported methods remain


package main

import (
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)

func main() {

c := {
User: "root", // replace this
Auth: []ssh.AuthMethod{
ssh.KeyboardInteractive(func(user, instruction string, questions []string, 
echos []bool) ([]string, error) {
// Just send the password back for all questions
answers := make([]string, len(questions))
for i, _ := range answers {
answers[i] = "12345678" // replace this
}

return answers, nil
}),
},
}

connection, err := ssh.Dial("tcp", "192.168.0.1:22", c) // replace this
if err != nil {
fmt.Println(err)
return
}

server, err := sftp.NewClient(connection)
if err != nil {
fmt.Println(err)
return
}

dir, err := server.ReadDir(".")
if err != nil {
fmt.Println(err)
return
}

for _, fi := range dir {
fmt.Println(fi.Name())
}
}

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Something like Java OSGi in Go language?

2017-02-06 Thread Vimal K

After the support for plugins in Go 1.8 is there any effort in community 
towards Go OSGi.

thanks,
Vimal

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] Is there something wrong with performance of select in a for loop

2017-02-06 Thread Jesper Louis Andersen
On Sun, Feb 5, 2017 at 7:59 PM  wrote:

> I make a test to see the performance of select, and found the result is
> not good.
>
> I make 1000 SeqQueue objects and run its messageLoop function (which does
> a small piece of work, and is listed as below) in 1000 separate go
> routines. The CPU cost is more than 20%.
> If I make the ticker 1 second, the CPU cost can slow down to about 2%.
>
>
>
The key difference in your Node.js vs Go test is this:

* Node.js is concurrent but has no inherent parallelism
* Go is concurrent but also employs parallelism by default

When a system has no parallelism, it can optimize for this. In particular,
there are many cases where you don't have to take a lock because no-one
else but the current (single) thread is able to manipulate the data. Also,
scheduling decisions can be immediate. Furthermore, Node.js has no
preemption but prefers cooperative behavior which eliminates a large number
of concurrent access patterns which needs lock protection.

In contrast, a system with parallelism has to lock data which needs to
synchronize, or it has to solve synchronization problems in other ways
through CAS-operations or the like.

Synchronization has overhead. It isn't free, and a test which essentially
focuses on synchronization is going to be slower in any system where you
truly has to guard against parallel access to data. Well written systems
tries hard to minimize synchronization to a few places so the overhead is
rather small. The benefit appears when your system gracefully scales to
multiple processor cores with no additional effort on your part.

The key is to employ Amdahl's law in the parallel case: minimize the
sequential part of your program as much as possible, so you get the best
parallel speedup behavior out of it. Or employ a slight rephrasing of
Amdahl's law "you can solve a problem K times larger in the same time"
which is sometimes easier since the computational overhead can benefit from
a larger data set in some cases (especially if it is a constant)

I'm willing to bet that as you start doing real work in your system, which
happens to be CPU-bound, then Go will easily outperform Node.js. Especially
because it will be able to easily utilize more than a single core of the
CPU.

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Is there something wrong with performance of select in a for loop

2017-02-06 Thread Didier Spezia

A few remarks:

1/ If you want to compare to node.js, please remove the CPU profiling 
option from the go program - it comes with some overhead.

2/ The comparison is not really fair.
node.js implements a unique event loop (everything runs on the same thread).
Go generally schedules the goroutines on multiple threads. Since all the 
goroutines target the same channels, there is some contention.
By default, Go uses a number of threads corresponding to the number of CPU 
cores, as exposed by the system.

If I run your Go program on my machine:

export GOMAXPROCS=32
> time ./main 
finished
./main  3.08s user 0.97s system >>> 40% <<< cpu 10.011 total

but:

export GOMAXPROCS=1
> time ./main
finished
./main  0.98s user 0.19s system >>> 11% <<< cpu 10.008 total

So when you run Go on 1 thread, the CPU consumption is divided by 4.

Regards,
Didier.


On Monday, February 6, 2017 at 6:56:41 AM UTC+1, fwan...@gmail.com wrote:
>
> For compared with nodejs:
> if I remove all the serverDone case, only left the ticker. The CPU is 5% 
> in my book, while nodejs cost 0.5%.
> The nodejs code is in the attachment.
>
>
> 在 2017年2月6日星期一 UTC+8上午3:00:15,fwan...@gmail.com写道:
>>
>> I make a test to see the performance of select, and found the result is 
>> not good.
>>
>> I make 1000 SeqQueue objects and run its messageLoop function (which does 
>> a small piece of work, and is listed as below) in 1000 separate go 
>> routines. The CPU cost is more than 20%.
>> If I make the ticker 1 second, the CPU cost can slow down to about 2%.
>>
>> With pprof, I see the most top cost are methods related to 
>> runtime.selectGo, runtime.lock.
>>
>> Who knows is there anything wrong in my case?
>>
>> func (this *SeqQueue) messageLoop() {
>> var ticker = time.NewTicker(100 * time.Millisecond)
>> defer ticker.Stop()
>> for {
>> select {
>> case <-serverDone:
>> return
>> case <-this.done:
>> return
>> case <-ticker.C:
>> this.tickCounter += 1
>> case message := <-this.messages:
>> this.messageCounter += 1
>> _ = message
>> }
>> }
>> }
>>
>>
>>
>>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] Re: Handshake failed when using builtin TLS package: no cipher suite supported by both client and server

2017-02-06 Thread James Bardin

What cipher quite is negotiated when you connect to the Heroku proxy?

What version of Go are you using on the server, and are you using the 
default tls.Config?

I don't have that client directly available to test with, but does your 
particular client show the expected information when you 
visit https://www.ssllabs.com/ssltest/viewMyClient.html?


On Sunday, February 5, 2017 at 3:44:47 AM UTC-5, Alexandr Emelin wrote:
>
> When using builtin TLS for http/websocket server I noticed that handshakes 
> from some old browser clients fail. The reason why I find this strange is 
> that other TLS implementations work with those connections without any 
> problems. I used ssllabs.com/ssltest/  to 
> emulate handshakes.
>
> To be more specific: clients using Chrome 49 on Windows XP SP3 can't 
> establish secure connection with my Go server. When I use Heroku reverse 
> proxy in front of the app - connection succesfully established using TLS 
> 1.2. In case of Go I see "*tls: no cipher suite supported by both client 
> and server*" message in server log.
>
> I investigated this a bit and found that actually client and server have 
> many cipher suites in common but none of them set in setCipherSuite 
> 
>  
> function. Here is list of supported and preference suites:
>
> Supported: []uint16{0xc02f, 0xcca8, 0xcc13, 0xc014, 0xc013, 0x9c, 0x35, 0x2f, 
> 0xa}
> Preference: []uint16{0x5600, 0xc02f, 0xc02b, 0xc030, 0xc02c, 0xc011, 0xc007, 
> 0xc013, 0xc009, 0xc014, 0xc00a, 0x9c, 0x9d, 0x5, 0x2f, 0x35, 0xc012, 0xa}
>
>
> They are all rejected by this code 
> 
>  (some 
> because there were no rsaSignOk set, some because there was no 
> rsaDecryptOk set).
>
> trying 0xc02f for version 0x303 
> reason rejected: !rsaSignOk
>
> trying 0xc013 for version 0x303 
> reason rejected: !rsaSignOk
>
> trying 0xc014 for version 0x303 
> reason rejected: !rsaSignOk
>
> trying 0x9c for version 0x303   
> reason rejected: !rsaDecryptOk
>
> trying 0x2f for version 0x303   
> reason rejected: !rsaDecryptOk
>
> trying 0x35 for version 0x303   
> reason rejected: !rsaDecryptOk
>
> trying 0xa for version 0x303
> reason rejected: !rsaDecryptOk
>
>
> I am not skilled in TLS area so looking for help – what's going on here, 
> why Go implementation does not support connections supported by other TLS 
> termination proxies?
>
>

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] jq (JSON Query) write support?

2017-02-06 Thread Konstantin Khomoutov
On Mon, 6 Feb 2017 02:20:31 -0800 (PST)
omarshariffdontlik...@gmail.com wrote:

> Just a quick one - anyone know of a JQ package that supports
> modifying values that match? I've found several packages that support
> reading values but none that support modifying values on match.

Quick searching on godoc [1] turns up [2] which appears to support what
you need: its querying functions return "JSON subtree" objects which
apparently can be modified (and marshaled); worth investigating.

1. https://godoc.org/?q=jsonpath
2. https://godoc.org/github.com/bmatsuo/go-jsontree

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] Re: Is there something wrong with performance of select in a for loop

2017-02-06 Thread Ilya Kostarev
Seems for me, you don't do any selection like in JS code, even any 
polling. Sure it would perform better. (Maybe I'm missing something, not 
so proficient in nodejs)


On 02/06/2017 08:56 AM, fwang2...@gmail.com wrote:

For compared with nodejs:
if I remove all the serverDone case, only left the ticker. The CPU is 
5% in my book, while nodejs cost 0.5%.

The nodejs code is in the attachment.



--
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 https://groups.google.com/d/optout.


Re: [go-nuts] About 64bits alignment

2017-02-06 Thread T L


On Monday, February 6, 2017 at 11:16:22 AM UTC, T L wrote:
>
>
>
> On Monday, February 6, 2017 at 6:43:04 PM UTC+8, T L wrote:
>>
>>
>>
>> On Monday, February 6, 2017 at 3:14:22 AM UTC+8, Ian Lance Taylor wrote:
>>>
>>> On Sun, Feb 5, 2017 at 10:52 AM, T L  wrote: 
>>> > Ian, thanks for the answers. 
>>> > 
>>> > But I still not very confirm on many points. 
>>> > 
>>> > Up to now, there are two places mention the alignments in Go. 
>>> > 
>>> > The first is in the end of Go spec: 
>>> > 
>>> > 
>>> > Size and alignment guarantees 
>>> > 
>>> > For the numeric types, the following sizes are guaranteed: 
>>> > 
>>> > type size in bytes 
>>> > 
>>> > byte, uint8, int8 1 
>>> > uint16, int16 2 
>>> > uint32, int32, float324 
>>> > uint64, int64, float64, complex64 8 
>>> > complex128   16 
>>> > 
>>> > The following minimal alignment properties are guaranteed: 
>>> > 
>>> > For a variable x of any type: unsafe.Alignof(x) is at least 1. 
>>> > For a variable x of struct type: unsafe.Alignof(x) is the largest of 
>>> all the 
>>> > values unsafe.Alignof(x.f) for each field f of x, but at least 1. 
>>> > For a variable x of array type: unsafe.Alignof(x) is the same as 
>>> > unsafe.Alignof(x[0]), but at least 1. 
>>> > 
>>> > A struct or array type has size zero if it contains no fields (or 
>>> elements, 
>>> > respectively) that have a size greater than zero. Two distinct 
>>> zero-size 
>>> > variables may have the same address in memory. 
>>> > 
>>> > 
>>> > The second is at the end of sync/atomic docs: 
>>> > 
>>> > 
>>> > On x86-32, the 64-bit functions use instructions unavailable before 
>>> the 
>>> > Pentium MMX. 
>>> > 
>>> > On non-Linux ARM, the 64-bit functions use instructions unavailable 
>>> before 
>>> > the ARMv6k core. 
>>> > 
>>> > On both ARM and x86-32, it is the caller's responsibility to arrange 
>>> for 
>>> > 64-bit alignment of 64-bit words accessed atomically. The first word 
>>> in a 
>>> > global variable or in an allocated struct or slice can be relied upon 
>>> to be 
>>> > 64-bit aligned. 
>>> > 
>>> > 
>>> > I feel the two are not enough to remove all my confusions. 
>>> > 
>>> > So could you help me remove the following confusions: 
>>> > 
>>> > 
>>> > 1. What does the "allocated struct or slice" mean? 
>>> > 
>>> > 
>>> > Currently, I think it means the structs or slices created by new, or 
>>> the 
>>> > structs or slices escape to heap. 
>>> > 
>>> > Is my understanding right? 
>>>
>>> Those cases are "allocated struct or slice," yes.  The phrase also 
>>> includes variables defined with a struct or slice type. 
>>>
>>>
>>> > 2. Are local 8-bytes variables 64bit aligned on 32bit OSes? 
>>> > 
>>> > 
>>> > I found there are many usages of the 64bit functions of atomic package 
>>> being 
>>> > used on local 8-bytes variables in go source. 
>>> > 
>>> > So I think the answer is yes. Right? 
>>>
>>> Yes. 
>>>
>>>
>> I installed a 32bit VM and found that local int64 and [N]int64 variables 
>> are not guaranteed to be 64bit aligned.
>> But the magic is, if the local int64 variables are passed to atomic 64bit 
>> functions, then they become 64bit aligned for sure. 
>> Quite magic.
>>
>> It looks when local int64 variables are escaped to heap if their 
>> addresses are passed to atomic 64bit functions.
>> And it looks 64bit words allocated on heap are always 64bit aligned, even 
>> on 32bit OSes.
>>
>>  
>>
>
> The same is for local structs which first field is a 64bit word. Such 
> local structs are also not guaranteed to be 64bit aligned.
> But if the addresses of the 64bit word fields are passed to atomic 64bit 
> functions, then the local structs will escape to heap,
> so the local structs become 64bit aligned on heap.
>
>
The same for local slices.

The full code:

// go version go1.7.5 linux/386

package main

import (
"sync/atomic"
)

func fa() {
println("== fa")
var b bool
var arr [5]int64
println(, ) // 0x1843bf73 0x1843bf74
}

func fa2() {
println("== fa2")
var b bool
var arr [5]int64
println(, ) // 0x1843bf57 0x184120f0
atomic.LoadInt64([0])
}

func fb() {
println("== fb")
var b bool
var x = new(int64)
println(, ) // 0x1843bf73 0x1843bf74
}

func fb2() {
println("== fb2")
var b bool
var x int64
println(, ) // 0x1843bf57 0x184120f0
atomic.LoadInt64()
}

func fc() {
println("== fc")
var b bool
var slc = make([]int64, 1)
println(, [0]) // 0x1843bf5b 0x1843bf5c
}

func fc2() {
println("== fc2")
var b bool
var slc = make([]int64, 1)
println(, [0]) // 0x1843bf37 0x1840e0e0
atomic.LoadInt64([0])
}

func fd() {
type T struct {
x int64
}
println("== fd")
var b bool
var t T
println(, ) // 0x1843bf33 0x1843bf34
}

func fd2() {
type T struct 

Re: [go-nuts] multipart/form-data and file size

2017-02-06 Thread Jesper Louis Andersen
I think it is a good idea. The only thing you should check before going for
it is what other clients are doing. Some times what is in the RFC is not
what has been implemented in reality. This can mean that if you start
following the RFC spec, you end up breaking some clients in the process,
which can be why such things are left out. In general, multipart is an
angry beehive of stuff.



On Mon, Feb 6, 2017 at 10:54 AM Manlio Perillo 
wrote:

> Hi.
>
> I have noted that the implementation of multipart.Reader.ReadForm *knows*
> the size of
> a file, but it just discards it.   Isn't it better if it make it available
> as a field in the FileHeader
> or, probably better as an additional Content-Length header?
>
> RFC 7578 says "The multipart/form-data media type does not support any
> MIME headerields in parts other than Content-Type, Content-Disposition, and
> (in limited circumstances) Content-Transfer-Encoding. Other header fields
> MUST NOT be included and MUST be ignored", however this does not mean
> that a client implementation can not add the Content-Length header.
>
> Knowing the size of an uploaded file without having to read the content
> again may be useful.
>
>
> Thanks
> Manlio
>
> --
> 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 https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] About 64bits alignment

2017-02-06 Thread T L


On Monday, February 6, 2017 at 6:43:04 PM UTC+8, T L wrote:
>
>
>
> On Monday, February 6, 2017 at 3:14:22 AM UTC+8, Ian Lance Taylor wrote:
>>
>> On Sun, Feb 5, 2017 at 10:52 AM, T L  wrote: 
>> > Ian, thanks for the answers. 
>> > 
>> > But I still not very confirm on many points. 
>> > 
>> > Up to now, there are two places mention the alignments in Go. 
>> > 
>> > The first is in the end of Go spec: 
>> > 
>> > 
>> > Size and alignment guarantees 
>> > 
>> > For the numeric types, the following sizes are guaranteed: 
>> > 
>> > type size in bytes 
>> > 
>> > byte, uint8, int8 1 
>> > uint16, int16 2 
>> > uint32, int32, float324 
>> > uint64, int64, float64, complex64 8 
>> > complex128   16 
>> > 
>> > The following minimal alignment properties are guaranteed: 
>> > 
>> > For a variable x of any type: unsafe.Alignof(x) is at least 1. 
>> > For a variable x of struct type: unsafe.Alignof(x) is the largest of 
>> all the 
>> > values unsafe.Alignof(x.f) for each field f of x, but at least 1. 
>> > For a variable x of array type: unsafe.Alignof(x) is the same as 
>> > unsafe.Alignof(x[0]), but at least 1. 
>> > 
>> > A struct or array type has size zero if it contains no fields (or 
>> elements, 
>> > respectively) that have a size greater than zero. Two distinct 
>> zero-size 
>> > variables may have the same address in memory. 
>> > 
>> > 
>> > The second is at the end of sync/atomic docs: 
>> > 
>> > 
>> > On x86-32, the 64-bit functions use instructions unavailable before the 
>> > Pentium MMX. 
>> > 
>> > On non-Linux ARM, the 64-bit functions use instructions unavailable 
>> before 
>> > the ARMv6k core. 
>> > 
>> > On both ARM and x86-32, it is the caller's responsibility to arrange 
>> for 
>> > 64-bit alignment of 64-bit words accessed atomically. The first word in 
>> a 
>> > global variable or in an allocated struct or slice can be relied upon 
>> to be 
>> > 64-bit aligned. 
>> > 
>> > 
>> > I feel the two are not enough to remove all my confusions. 
>> > 
>> > So could you help me remove the following confusions: 
>> > 
>> > 
>> > 1. What does the "allocated struct or slice" mean? 
>> > 
>> > 
>> > Currently, I think it means the structs or slices created by new, or 
>> the 
>> > structs or slices escape to heap. 
>> > 
>> > Is my understanding right? 
>>
>> Those cases are "allocated struct or slice," yes.  The phrase also 
>> includes variables defined with a struct or slice type. 
>>
>>
>> > 2. Are local 8-bytes variables 64bit aligned on 32bit OSes? 
>> > 
>> > 
>> > I found there are many usages of the 64bit functions of atomic package 
>> being 
>> > used on local 8-bytes variables in go source. 
>> > 
>> > So I think the answer is yes. Right? 
>>
>> Yes. 
>>
>>
> I installed a 32bit VM and found that local int64 and [N]int64 variables 
> are not guaranteed to be 64bit aligned.
> But the magic is, if the local int64 variables are passed to atomic 64bit 
> functions, then they become 64bit aligned for sure. 
> Quite magic.
>
> It looks when local int64 variables are escaped to heap if their addresses 
> are passed to atomic 64bit functions.
> And it looks 64bit words allocated on heap are always 64bit aligned, even 
> on 32bit OSes.
>
>  
>

The same is for local structs which first field is a 64bit word. Such local 
structs are also not guaranteed to be 64bit aligned.
But if the addresses of the 64bit word fields are passed to atomic 64bit 
functions, then the local structs will escape to heap,
so the local structs become 64bit aligned on heap.

 

>
>> > 3. Are expvar.Int and expvar.Float safe to be embedded in other structs 
>> on 
>> > 32bit OSes? 
>> > 
>> > 
>> > I think the answer is no. Is my opinion right? 
>>
>> You could embed them as the first field of a struct (if you were then 
>> careful to not embed that struct, (except as the first field)). 
>>
>> It would not be portable to embed them as anything other than the first 
>> field. 
>>
>> I think this is problematic, and it would be nice to figure out a way to 
>> fix it. 
>>
>> Ian 
>>
>

-- 
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 https://groups.google.com/d/optout.


Re: [go-nuts] About 64bits alignment

2017-02-06 Thread T L


On Monday, February 6, 2017 at 3:14:22 AM UTC+8, Ian Lance Taylor wrote:
>
> On Sun, Feb 5, 2017 at 10:52 AM, T L  
> wrote: 
> > Ian, thanks for the answers. 
> > 
> > But I still not very confirm on many points. 
> > 
> > Up to now, there are two places mention the alignments in Go. 
> > 
> > The first is in the end of Go spec: 
> > 
> > 
> > Size and alignment guarantees 
> > 
> > For the numeric types, the following sizes are guaranteed: 
> > 
> > type size in bytes 
> > 
> > byte, uint8, int8 1 
> > uint16, int16 2 
> > uint32, int32, float324 
> > uint64, int64, float64, complex64 8 
> > complex128   16 
> > 
> > The following minimal alignment properties are guaranteed: 
> > 
> > For a variable x of any type: unsafe.Alignof(x) is at least 1. 
> > For a variable x of struct type: unsafe.Alignof(x) is the largest of all 
> the 
> > values unsafe.Alignof(x.f) for each field f of x, but at least 1. 
> > For a variable x of array type: unsafe.Alignof(x) is the same as 
> > unsafe.Alignof(x[0]), but at least 1. 
> > 
> > A struct or array type has size zero if it contains no fields (or 
> elements, 
> > respectively) that have a size greater than zero. Two distinct zero-size 
> > variables may have the same address in memory. 
> > 
> > 
> > The second is at the end of sync/atomic docs: 
> > 
> > 
> > On x86-32, the 64-bit functions use instructions unavailable before the 
> > Pentium MMX. 
> > 
> > On non-Linux ARM, the 64-bit functions use instructions unavailable 
> before 
> > the ARMv6k core. 
> > 
> > On both ARM and x86-32, it is the caller's responsibility to arrange for 
> > 64-bit alignment of 64-bit words accessed atomically. The first word in 
> a 
> > global variable or in an allocated struct or slice can be relied upon to 
> be 
> > 64-bit aligned. 
> > 
> > 
> > I feel the two are not enough to remove all my confusions. 
> > 
> > So could you help me remove the following confusions: 
> > 
> > 
> > 1. What does the "allocated struct or slice" mean? 
> > 
> > 
> > Currently, I think it means the structs or slices created by new, or the 
> > structs or slices escape to heap. 
> > 
> > Is my understanding right? 
>
> Those cases are "allocated struct or slice," yes.  The phrase also 
> includes variables defined with a struct or slice type. 
>
>
> > 2. Are local 8-bytes variables 64bit aligned on 32bit OSes? 
> > 
> > 
> > I found there are many usages of the 64bit functions of atomic package 
> being 
> > used on local 8-bytes variables in go source. 
> > 
> > So I think the answer is yes. Right? 
>
> Yes. 
>
>
I installed a 32bit VM and found that local int64 and [N]int64 variables 
are not guaranteed to be 64bit aligned.
But the magic is, if the local int64 variables are passed to atomic 64bit 
functions, then they become 64bit aligned for sure. 
Quite magic.

It looks when local int64 variables are escaped to heap if their addresses 
are passed to atomic 64bit functions.
And it looks 64bit words allocated on heap are always 64bit aligned, even 
on 32bit OSes.

 

>
> > 3. Are expvar.Int and expvar.Float safe to be embedded in other structs 
> on 
> > 32bit OSes? 
> > 
> > 
> > I think the answer is no. Is my opinion right? 
>
> You could embed them as the first field of a struct (if you were then 
> careful to not embed that struct, (except as the first field)). 
>
> It would not be portable to embed them as anything other than the first 
> field. 
>
> I think this is problematic, and it would be nice to figure out a way to 
> fix it. 
>
> Ian 
>

-- 
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 https://groups.google.com/d/optout.


[go-nuts] jq (JSON Query) write support?

2017-02-06 Thread omarshariffdontlikeit
Just a quick one - anyone know of a JQ package that supports modifying 
values that match? I've found several packages that support reading values 
but none that support modifying values on match.

Cheers!

-- 
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 https://groups.google.com/d/optout.


[go-nuts] multipart/form-data and file size

2017-02-06 Thread Manlio Perillo
Hi.

I have noted that the implementation of multipart.Reader.ReadForm *knows* 
the size of
a file, but it just discards it.   Isn't it better if it make it available 
as a field in the FileHeader
or, probably better as an additional Content-Length header?

RFC 7578 says "The multipart/form-data media type does not support any MIME 
headerields in parts other than Content-Type, Content-Disposition, and (in 
limited circumstances) Content-Transfer-Encoding. Other header fields MUST 
NOT be included and MUST be ignored", however this does not mean that a 
client implementation can not add the Content-Length header.

Knowing the size of an uploaded file without having to read the content 
again may be useful.


Thanks
Manlio

-- 
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 https://groups.google.com/d/optout.


[go-nuts] [ANN] .proto file (2,3) parser and formatter (protofmt)

2017-02-06 Thread Ernest Micklei
Hi,

This package was created to format .proto files but could also be used to 
write code generators (eg. HTML doc, mocks).

https://github.com/emicklei/proto


Example from the unittest_proto3_arena.proto

// Test messages for packed fields
message TestPackedTypes {
 repeated   int32 packed_int32=  90 [packed=true];
 repeated   int64 packed_int64=  91 [packed=true];
 repeated  uint32 packed_uint32   =  92 [packed=true];
 repeated  uint64 packed_uint64   =  93 [packed=true];
 repeated  sint32 packed_sint32   =  94 [packed=true];
 repeated  sint64 packed_sint64   =  95 [packed=true];
 repeated fixed32 packed_fixed32  =  96 [packed=true];
 repeated fixed64 packed_fixed64  =  97 [packed=true];
 repeatedsfixed32 packed_sfixed32 =  98 [packed=true];
 repeatedsfixed64 packed_sfixed64 =  99 [packed=true];
 repeated   float packed_float= 100 [packed=true];
 repeated  double packed_double   = 101 [packed=true];
 repeatedbool packed_bool = 102 [packed=true];
 repeated ForeignEnum packed_enum = 103 [packed=true];
}

MIT License. Contributions welcome.

^ Ernest

-- 
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 https://groups.google.com/d/optout.