[go-nuts] Concurrent map error in net/http/trasport

2016-11-10 Thread James Pettyjohn
I ran into this on go 1.6.2 amd64, seems unlikely this is a core issue and 
I need to look else where in the project but has anyone seen this before?

fatal error: concurrent map read and map write

goroutine 21619 [running]:
runtime.throw(0xfefc00, 0x21)
/usr/local/go/src/runtime/panic.go:547 +0x90 fp=0xc822727ac0 
sp=0xc822727aa8
runtime.mapaccess1(0xca4a00, 0xc828346120, 0xc822727c58, 0x1931c00)
/usr/local/go/src/runtime/hashmap.go:289 +0x5a fp=0xc822727b08 
sp=0xc822727ac0
net/http.(*Transport).tryPutIdleConn(0xc822c00b40, 0xc82181fc70, 0x0, 0x0)
/usr/local/go/src/net/http/transport.go:562 +0x41e fp=0xc822727c90 
sp=0xc822727b08
net/http.(*persistConn).readLoop.func2(0xc82181fc70)
/usr/local/go/src/net/http/transport.go:1053 +0x32 fp=0xc822727cd0 
sp=0xc822727c90
net/http.(*persistConn).readLoop(0xc82181fc70)
/usr/local/go/src/net/http/transport.go:1189 +0xc5d fp=0xc822727fa8 
sp=0xc822727cd0
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc822727fb0 
sp=0xc822727fa8
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:857 +0x10a6

-- 
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] SCL, a language that extends the Hashicorp Configuration Language in the same sort of way Sass extends CSS

2016-11-10 Thread Paul M Fox


GitHub repo: https://github.com/homemade/scl
Language reference: https://github.com/homemade/scl/wiki
GoDoc: https://godoc.org/github.com/homemade/scl

The Sepia Configuration Language is a simple, declarative, semi-functional, 
self-documenting language that extends HashiCorp's HCL 
. The syntax of SCL is concise, intuitive 
and flexible. Critically, it also validates much of your configuration by 
design. SCL transpiles to HCL and, like CSS and Sass, any properly 
formatted HCL is valid SCL. If you have an existing HCL setup, you can 
transplant it to SCL directly and then start making use of the code 
organisation, mixins, and properly scoped variables that SCL offers.


SCL was built to support a larger, config-driven application, but we've 
found lots of uses for it. There are libraries for Terraform and Hugo in 
the works, which will hopefully appear shortly. The software is fairly new 
as a standalone package, but it has been well tested and used in 
production. There are still improvements to be made, so bug reports, 
suggestions and feature requests are very welcome!


PMF

-- 
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: [ANN] SCL, a language that extends the Hashicorp Configuration Language in the same sort of way Sass extends CSS

2016-11-10 Thread mhhcbon
seems a great idea to bring a factorized version of this sort of solution.

On Thursday, November 10, 2016 at 10:32:13 AM UTC+1, Paul M Fox wrote:
>
>
>
> GitHub repo: https://github.com/homemade/scl
> Language reference: https://github.com/homemade/scl/wiki
> GoDoc: https://godoc.org/github.com/homemade/scl
>
> The Sepia Configuration Language is a simple, declarative, 
> semi-functional, self-documenting language that extends HashiCorp's HCL 
> . The syntax of SCL is concise, 
> intuitive and flexible. Critically, it also validates much of your 
> configuration by design. SCL transpiles to HCL and, like CSS and Sass, any 
> properly formatted HCL is valid SCL. If you have an existing HCL setup, you 
> can transplant it to SCL directly and then start making use of the code 
> organisation, mixins, and properly scoped variables that SCL offers.
>
>
> SCL was built to support a larger, config-driven application, but we've 
> found lots of uses for it. There are libraries for Terraform and Hugo in 
> the works, which will hopefully appear shortly. The software is fairly new 
> as a standalone package, but it has been well tested and used in 
> production. There are still improvements to be made, so bug reports, 
> suggestions and feature requests are very welcome!
>
>
> PMF
>

-- 
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: Why google cloud vision api cause memory issue when it is failed to detect

2016-11-10 Thread nova6112


try{
byte[] imageBytes=mymultipart imagefile;

httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = GsonFactory.getDefaultInstance();

Vision.Builder builder = new Vision.Builder(httpTransport, jsonFactory, 
null);
builder.setVisionRequestInitializer(new
VisionRequestInitializer(myvisionAPIkey));
Vision vision = builder.build();

AnnotateImageRequest request =
new AnnotateImageRequest()
.setImage(new Image().encodeContent(imageBytes))
.setFeatures(ImmutableList.of(
new Feature()
.setType("TEXT_DETECTION")
.setMaxResults(1),
new Feature()
.setType("LOGO_DETECTION")
.setMaxResults(1)));
Vision.Images.Annotate annotate =
vision.images()
.annotate(new 
BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
BatchAnnotateImagesResponse batchResponse = annotate.execute();
}catch(Exception e){
e.printStackTrace();
}


This is my code. but its look when i use a image without any Letters or 
many users using this call. not sure in which scenario this happens and i 
can't replicate.


On Thursday, November 10, 2016 at 1:23:36 AM UTC+5:30, Dave Cheney wrote:
>
> Can you please post the full stack trace of the crash and a piece of code 
> to reproduce the issue.
>
> Thanks.
>
> On Thursday, 10 November 2016 00:26:03 UTC+11, nova...@gmail.com wrote:
>>
>> Hi i am using Google Cloud vision API in my server side (JAVA) but when 
>> no results found my server got crashed not sure why it is happening could 
>> anyone help me?
>>
>> Thanks in advance
>>
>

-- 
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 generate "pipelines"

2016-11-10 Thread Paul Jolly
Hi - wondering whether anyone knows of any tooling that helps with 
"pipelines" (probably not a great choice of phrase) of go generate-able 
code. 

Specifically the case where the output of one go generate program is code 
which is itself go generate-able (and hence requires another invocation of 
go generate)

There are various strategies I can think of for handling this situation, 
but wanted to check if there was prior art out there before starting 
something home-baked.

Thanks,


Paul

-- 
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] JSON parser

2016-11-10 Thread Simon Ritchie
I'm also not sure what you are trying to do.  However, I think I can see a bug 
in your code.

First you run a database query to get a list of values from a field called 
data.  This could produce up to 10 values.

Next you have a loop which runs through the values and discards them.  At the 
end of the loop, you have the data field from the last record, and you have 
thrown away all the others.  Is this what you want?

Finally, you unzip the last data field.

So if your table contains 100 records, you will get 10 of them, throw away the 
first 9 records and unzip the data from the last one.

I hope this helps.

-- 
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] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendoerfer
Hi all,

while working on instrumenting my application, I ran into the fact that 
capturing metrics such as status codes from my own http.Handlers is 
surprisingly difficult to get right.

Therefor I created a package that hopefully avoids most of the common 
pitfalls. 

https://github.com/felixge/httpsnoop

I would love for net/http experts to take a look at the "Why this package 
exists" section of the README, as well as the horrible hack required to 
make things work:

https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163

Please let me know if you have suggestions for simpler approaches and/or 
spot any bugs in my implementation.

Thanks a lot!
Felix Geisendörfer

-- 
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] why "iota"?

2016-11-10 Thread Konstantin Khomoutov
On Thu, 10 Nov 2016 10:27:49 +1030
Dan Kortschak  wrote:

> On Wed, 2016-11-09 at 09:30 -0500, Marvin Renich wrote:
> > Iota is pronounced eye-OH-tuh.
>
> Or yoh-ta (like Yoda, but with s/d/t/) if not in America.
>

I concur that here in Russia we taught to spell it yoh-ta on our math
high school courses.

-- 
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] Why google cloud vision api cause memory issue when it is failed to detect

2016-11-10 Thread Pietro Gagliardi
And what's the code on the client side, which I assume is in Go?
> On Nov 10, 2016, at 5:26 AM, nova6...@gmail.com wrote:
> 
> try{
> byte[] imageBytes=mymultipart imagefile;
> 
> httpTransport = GoogleNetHttpTransport.newTrustedTransport();
> JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
> 
> Vision.Builder builder = new Vision.Builder(httpTransport, jsonFactory, 
> null);
> builder.setVisionRequestInitializer(new
> VisionRequestInitializer(myvisionAPIkey));
> Vision vision = builder.build();
> 
> AnnotateImageRequest request =
> new AnnotateImageRequest()
> .setImage(new Image().encodeContent(imageBytes))
> .setFeatures(ImmutableList.of(
> new Feature()
> .setType("TEXT_DETECTION")
> .setMaxResults(1),
> new Feature()
> .setType("LOGO_DETECTION")
> .setMaxResults(1)));
> Vision.Images.Annotate annotate =
> vision.images()
> .annotate(new 
> BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
> BatchAnnotateImagesResponse batchResponse = annotate.execute();
> }catch(Exception e){
> e.printStackTrace();
> }
> 
> This is my code. but its look when i use a image without any Letters or many 
> users using this call. not sure in which scenario this happens and i can't 
> replicate.
> 
> 
> On Thursday, November 10, 2016 at 1:23:36 AM UTC+5:30, Dave Cheney wrote:
> Can you please post the full stack trace of the crash and a piece of code to 
> reproduce the issue.
> 
> Thanks.
> 
> On Thursday, 10 November 2016 00:26:03 UTC+11, nova...@gmail.com <> wrote:
> Hi i am using Google Cloud vision API in my server side (JAVA) but when no 
> results found my server got crashed not sure why it is happening could anyone 
> help me?
> 
> Thanks in advance
> 
> -- 
> 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: Implementation status of database/sql changes

2016-11-10 Thread Viktor Kojouharov
I think it's the job of database/sql to extract any placeholders from the 
sql string and present them in a standardized way to each driver. It would 
be pointless if they had to reinvent the wheel every time. As for actually 
parsing SQL, it's not overly difficult. Obviously, search and replace isn't 
going to cut it :)

On Wednesday, November 9, 2016 at 5:21:04 PM UTC+2, mattn wrote:
>
>
> On Wednesday, November 9, 2016 at 6:00:45 PM UTC+9, Viktor Kojouharov 
> wrote:
>>
>> Why doesn't the change standardize the placeholder format? The driver can 
>> easily convert from a standard "[SOME-RUNE]PLACEHOLDER" to whatever the 
>> actual database supports. Having a non-standard format just introduces 
>> confusion and difficulty for the users of the api.
>>
>
> Not easy. The driver should parse SQL and replace placeholders in go.
>
> SELECT * FROM FOO WHERE NAME=':foo'
>
> Driver can't replace :foo because this is value not placeholder.
>
>

-- 
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: Why google cloud vision api cause memory issue when it is failed to detect

2016-11-10 Thread nova6112
Java language it is Web application

On Wednesday, November 9, 2016 at 6:56:03 PM UTC+5:30, nova...@gmail.com 
wrote:
>
> Hi i am using Google Cloud vision API in my server side (JAVA) but when no 
> results found my server got crashed not sure why it is happening could 
> anyone help me?
>
> Thanks in advance
>

-- 
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] Why google cloud vision api cause memory issue when it is failed to detect

2016-11-10 Thread nova6112
Java... it is web application...

On Thursday, November 10, 2016 at 6:13:56 PM UTC+5:30, Pietro Gagliardi 
(andlabs) wrote:
>
> And what's the code on the client side, which I assume is in Go?
>
> On Nov 10, 2016, at 5:26 AM, nova...@gmail.com  wrote:
>
> try{
> byte[] imageBytes=mymultipart imagefile;
>
> httpTransport = GoogleNetHttpTransport.newTrustedTransport();
> JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
>
> Vision.Builder builder = new Vision.Builder(httpTransport, jsonFactory, 
> null);
> builder.setVisionRequestInitializer(new
> VisionRequestInitializer(myvisionAPIkey));
> Vision vision = builder.build();
>
> AnnotateImageRequest request =
> new AnnotateImageRequest()
> .setImage(new Image().encodeContent(imageBytes))
> .setFeatures(ImmutableList.of(
> new Feature()
> .setType("TEXT_DETECTION")
> .setMaxResults(1),
> new Feature()
> .setType("LOGO_DETECTION")
> .setMaxResults(1)));
> Vision.Images.Annotate annotate =
> vision.images()
> .annotate(new 
> BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
> BatchAnnotateImagesResponse batchResponse = annotate.execute();
> }catch(Exception e){
> e.printStackTrace();
> }
>
>
> This is my code. but its look when i use a image without any Letters or 
> many users using this call. not sure in which scenario this happens and i 
> can't replicate.
>
>
> On Thursday, November 10, 2016 at 1:23:36 AM UTC+5:30, Dave Cheney wrote:
>>
>> Can you please post the full stack trace of the crash and a piece of code 
>> to reproduce the issue.
>>
>> Thanks.
>>
>> On Thursday, 10 November 2016 00:26:03 UTC+11, nova...@gmail.com wrote:
>>>
>>> Hi i am using Google Cloud vision API in my server side (JAVA) but when 
>>> no results found my server got crashed not sure why it is happening could 
>>> anyone help me?
>>>
>>> Thanks in advance
>>>
>>
> -- 
> 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.


Re: [go-nuts] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Ian Davis

On Thu, Nov 10, 2016, at 11:09 AM, Felix Geisendoerfer wrote:
> I would love for net/http experts to take a look at the "Why this
> package exists" section of the README, as well as the horrible hack
> required to make things work:
>
> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163
>
> Please let me know if you have suggestions for simpler approaches
> and/or spot any bugs in my implementation.
>

Did you think about performing a type assertion in the rw struct methods
like this:

func (w *rw) Flush() {
if f, ok := w.w.(http.Flusher); ok {
f.Flush()
}
}

I haven't tried it myself, but it's what came to mind when reading your
Wrap "abomination" (as you call it in the code).


-- 
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] Slow 64 bit integer division on amd64

2016-11-10 Thread alb . donizetti
When you do a DIV r32 in 64bit mode the result will be saved in
EAX but this means that you can only do that if the high word 
of the dividend is smaller that the divisor. 

You can't unconditionally replace uint32(A / uint64(B)) with a 
DIV r32 instruction because if A is big (take 2**62) and B is 
small (take 13) then the quotient will overflow EAX.

A.



Il giorno martedì 8 novembre 2016 06:18:02 UTC+1, ra...@cockroachlabs.com 
ha scritto:
>
> Sorry to revive an old thread.  One thing to note is that dividing a 
> 64-bit by a 32-bit is much faster than dividing a 64-bit by a 64-bit, at 
> least on recent Intel platforms. Unfortunately there is no valid way to 
> express that kind of calculation in Go..
>
> Is the compiler/optimizer smart enough to figure out it can do that if you 
> do something like `uint32(a / uint64(b))` where a is `uint64` and b is 
> `uint32`? (the result of that expression can be computed using the 32-bit 
> version of DIV)
>
> On Saturday, January 19, 2013 at 6:10:34 PM UTC-5, Michael Jones wrote:
>>
>> Integer division is slow. 
>>
>> It is the unloved arithmetic operation in CPU design because of its low 
>> frequency of occurrence in the instruction stream. It is the one--if you 
>> remember childhood schooling--that was "not like the others" in its 
>> mechanism: there was lots of guessing using leading digits, trial divisors, 
>> and so on. This awkwardness exists even in base 2 (though much less) and 
>> means that any division circuit my have to do at least one "fixup" step. (A 
>> good design does either zero or one fixup, but that one means more work and 
>> plausibly an extra cycle on what is already a long cycle-count activity.)
>>
>> As one specific example, when adding and subtracting were 1 cycle and 
>> multiply was 4, a 32-bit integer division required 19 cycles.
>>
>>
>> On Sat, Jan 19, 2013 at 1:25 PM, minux  wrote:
>>
>>>
>>>
>>> On Sun, Jan 20, 2013 at 5:22 AM, Jan Mercl <0xj...@gmail.com> wrote:
>>>
 On Sat, Jan 19, 2013 at 10:13 PM, Dominik Honnef  
 wrote:

 Cannot reproduce here (Xeon on dont-know-how-much GHz)

 jnml@fsc-r630:~/src/tmp/20130119$ cat a_test.go
 package main

 import (
 "testing"
 )

 func BenchmarkBase(b *testing.B) {
 var x int32
 for i := 1; i < b.N; i++ {
 }
 _ = x
 }

 func BenchmarkInt(b *testing.B) {
 var x int
 for i := 1; i < b.N; i++ {
 x /= 42
 }
 _ = x
 }

>>> division by a constant should be turned into multiplication by magic 
>>> constants
>>> by the Go compiler just to avoid the costly divide instruction.
>>>
>>> you can verify that by 'go tool 6g -S'.
>>>
>>> -- 
>>>  
>>>  
>>>
>>
>>
>>
>> -- 
>> Michael T. Jones | Chief Technology Advocate  | m...@google.com |  +1 
>> 650-335-5765
>>
>

-- 
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] Slow 64 bit integer division on amd64

2016-11-10 Thread radu
I don't understand. We are truncating the result to 32-bits either way. 
What's the point of computing the entire 64-bits of the result just to 
throw away the high 32?

In your example, A=2^62 and B=13`, `uint32(A / uint64(B))` is (2^62 / 13) % 
2^32 which I thought is exactly the result of DIV r32.

-Radu

On Thursday, November 10, 2016 at 8:46:02 AM UTC-5, alb.do...@gmail.com 
wrote:
>
> When you do a DIV r32 in 64bit mode the result will be saved in
> EAX but this means that you can only do that if the high word 
> of the dividend is smaller that the divisor. 
>
> You can't unconditionally replace uint32(A / uint64(B)) with a 
> DIV r32 instruction because if A is big (take 2**62) and B is 
> small (take 13) then the quotient will overflow EAX.
>
> A.
>
>
>
> Il giorno martedì 8 novembre 2016 06:18:02 UTC+1, ra...@cockroachlabs.com 
> ha scritto:
>>
>> Sorry to revive an old thread.  One thing to note is that dividing a 
>> 64-bit by a 32-bit is much faster than dividing a 64-bit by a 64-bit, at 
>> least on recent Intel platforms. Unfortunately there is no valid way to 
>> express that kind of calculation in Go..
>>
>> Is the compiler/optimizer smart enough to figure out it can do that if 
>> you do something like `uint32(a / uint64(b))` where a is `uint64` and b is 
>> `uint32`? (the result of that expression can be computed using the 32-bit 
>> version of DIV)
>>
>> On Saturday, January 19, 2013 at 6:10:34 PM UTC-5, Michael Jones wrote:
>>>
>>> Integer division is slow. 
>>>
>>> It is the unloved arithmetic operation in CPU design because of its low 
>>> frequency of occurrence in the instruction stream. It is the one--if you 
>>> remember childhood schooling--that was "not like the others" in its 
>>> mechanism: there was lots of guessing using leading digits, trial divisors, 
>>> and so on. This awkwardness exists even in base 2 (though much less) and 
>>> means that any division circuit my have to do at least one "fixup" step. (A 
>>> good design does either zero or one fixup, but that one means more work and 
>>> plausibly an extra cycle on what is already a long cycle-count activity.)
>>>
>>> As one specific example, when adding and subtracting were 1 cycle and 
>>> multiply was 4, a 32-bit integer division required 19 cycles.
>>>
>>>
>>> On Sat, Jan 19, 2013 at 1:25 PM, minux  wrote:
>>>


 On Sun, Jan 20, 2013 at 5:22 AM, Jan Mercl <0xj...@gmail.com> wrote:

> On Sat, Jan 19, 2013 at 10:13 PM, Dominik Honnef <
> domi...@fork-bomb.org> wrote:
>
> Cannot reproduce here (Xeon on dont-know-how-much GHz)
>
> jnml@fsc-r630:~/src/tmp/20130119$ cat a_test.go
> package main
>
> import (
> "testing"
> )
>
> func BenchmarkBase(b *testing.B) {
> var x int32
> for i := 1; i < b.N; i++ {
> }
> _ = x
> }
>
> func BenchmarkInt(b *testing.B) {
> var x int
> for i := 1; i < b.N; i++ {
> x /= 42
> }
> _ = x
> }
>
 division by a constant should be turned into multiplication by magic 
 constants
 by the Go compiler just to avoid the costly divide instruction.

 you can verify that by 'go tool 6g -S'.

 -- 
  
  

>>>
>>>
>>>
>>> -- 
>>> Michael T. Jones | Chief Technology Advocate  | m...@google.com |  +1 
>>> 650-335-5765
>>>
>>

-- 
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] Slow 64 bit integer division on amd64

2016-11-10 Thread alb . donizetti
If the div overflow, it will trigger and hardware exception. 

Il giorno giovedì 10 novembre 2016 15:01:06 UTC+1, ra...@cockroachlabs.com 
ha scritto:
>
> I don't understand. We are truncating the result to 32-bits either way. 
> What's the point of computing the entire 64-bits of the result just to 
> throw away the high 32?
>
> In your example, A=2^62 and B=13`, `uint32(A / uint64(B))` is (2^62 / 13) 
> % 2^32 which I thought is exactly the result of DIV r32.
>
> -Radu
>
> On Thursday, November 10, 2016 at 8:46:02 AM UTC-5, alb.do...@gmail.com 
> wrote:
>>
>> When you do a DIV r32 in 64bit mode the result will be saved in
>> EAX but this means that you can only do that if the high word 
>> of the dividend is smaller that the divisor. 
>>
>> You can't unconditionally replace uint32(A / uint64(B)) with a 
>> DIV r32 instruction because if A is big (take 2**62) and B is 
>> small (take 13) then the quotient will overflow EAX.
>>
>> A.
>>
>>
>>
>> Il giorno martedì 8 novembre 2016 06:18:02 UTC+1, ra...@cockroachlabs.com 
>> ha scritto:
>>>
>>> Sorry to revive an old thread.  One thing to note is that dividing a 
>>> 64-bit by a 32-bit is much faster than dividing a 64-bit by a 64-bit, at 
>>> least on recent Intel platforms. Unfortunately there is no valid way to 
>>> express that kind of calculation in Go..
>>>
>>> Is the compiler/optimizer smart enough to figure out it can do that if 
>>> you do something like `uint32(a / uint64(b))` where a is `uint64` and b is 
>>> `uint32`? (the result of that expression can be computed using the 32-bit 
>>> version of DIV)
>>>
>>> On Saturday, January 19, 2013 at 6:10:34 PM UTC-5, Michael Jones wrote:

 Integer division is slow. 

 It is the unloved arithmetic operation in CPU design because of its low 
 frequency of occurrence in the instruction stream. It is the one--if you 
 remember childhood schooling--that was "not like the others" in its 
 mechanism: there was lots of guessing using leading digits, trial 
 divisors, 
 and so on. This awkwardness exists even in base 2 (though much less) and 
 means that any division circuit my have to do at least one "fixup" step. 
 (A 
 good design does either zero or one fixup, but that one means more work 
 and 
 plausibly an extra cycle on what is already a long cycle-count activity.)

 As one specific example, when adding and subtracting were 1 cycle and 
 multiply was 4, a 32-bit integer division required 19 cycles.


 On Sat, Jan 19, 2013 at 1:25 PM, minux  wrote:

>
>
> On Sun, Jan 20, 2013 at 5:22 AM, Jan Mercl <0xj...@gmail.com> wrote:
>
>> On Sat, Jan 19, 2013 at 10:13 PM, Dominik Honnef <
>> domi...@fork-bomb.org> wrote:
>>
>> Cannot reproduce here (Xeon on dont-know-how-much GHz)
>>
>> jnml@fsc-r630:~/src/tmp/20130119$ cat a_test.go
>> package main
>>
>> import (
>> "testing"
>> )
>>
>> func BenchmarkBase(b *testing.B) {
>> var x int32
>> for i := 1; i < b.N; i++ {
>> }
>> _ = x
>> }
>>
>> func BenchmarkInt(b *testing.B) {
>> var x int
>> for i := 1; i < b.N; i++ {
>> x /= 42
>> }
>> _ = x
>> }
>>
> division by a constant should be turned into multiplication by magic 
> constants
> by the Go compiler just to avoid the costly divide instruction.
>
> you can verify that by 'go tool 6g -S'.
>
> -- 
>  
>  
>



 -- 
 Michael T. Jones | Chief Technology Advocate  | m...@google.com |  +1 
 650-335-5765

>>>

-- 
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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer
Yes, I thought about it :).

Did you read the "Why this package exists” section of the README?

The problem with this approach is that an application’s behavior might change 
merely because the method is present. E.g. imagine an application doing this:

```
_, ok := w.(http.Flusher)
if ok {
  w.Write([]byte(“I don’t like talking to flushers!"))
  return
}
```

Perhaps I’m paranoid, but IMO introducing instrumentation into the most 
critical path of a large application is something one should not take too 
lightly. It’s really easy to break some obscure handler somewhere without 
realizing it.

Cheers
Felix

> On 10 Nov 2016, at 14:44, Ian Davis  wrote:
> 
> 
> On Thu, Nov 10, 2016, at 11:09 AM, Felix Geisendoerfer wrote:
>> I would love for net/http experts to take a look at the "Why this package 
>> exists" section of the README, as well as the horrible hack required to make 
>> things work:
>> 
>> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163 
>> 
>> 
>> Please let me know if you have suggestions for simpler approaches and/or 
>> spot any bugs in my implementation.
>> 
> 
> Did you think about performing a type assertion in the rw struct methods like 
> this:
> 
> func (w *rw) Flush() {
> if f, ok := w.w.(http.Flusher); ok {
> f.Flush()
> }
> }
> 
> I haven't tried it myself, but it's what came to mind when reading your Wrap 
> "abomination" (as you call it in the code).
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/-I5IZgJosYE/unsubscribe 
> .
> To unsubscribe from this group and all its topics, 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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Ian Davis

On Thu, Nov 10, 2016, at 02:21 PM, Felix Geisendörfer wrote:
> Yes, I thought about it :).
>
> Did you read the "Why this package exists” section of the README?

Yes but obviously not closely enough :)

Kubernetes takes a hybrid approach:

https://github.com/kubernetes/kubernetes/blob/master/pkg/apiserver/metrics/metrics.go#L84

-- 
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] Slow 64 bit integer division on amd64

2016-11-10 Thread radu
Ah, I missed that, thanks!

On Thursday, November 10, 2016 at 9:05:53 AM UTC-5, alb.do...@gmail.com 
wrote:
>
> If the div overflow, it will trigger and hardware exception. 
>
> Il giorno giovedì 10 novembre 2016 15:01:06 UTC+1, ra...@cockroachlabs.com 
> ha scritto:
>>
>> I don't understand. We are truncating the result to 32-bits either way. 
>> What's the point of computing the entire 64-bits of the result just to 
>> throw away the high 32?
>>
>> In your example, A=2^62 and B=13`, `uint32(A / uint64(B))` is (2^62 / 13) 
>> % 2^32 which I thought is exactly the result of DIV r32.
>>
>> -Radu
>>
>> On Thursday, November 10, 2016 at 8:46:02 AM UTC-5, alb.do...@gmail.com 
>> wrote:
>>>
>>> When you do a DIV r32 in 64bit mode the result will be saved in
>>> EAX but this means that you can only do that if the high word 
>>> of the dividend is smaller that the divisor. 
>>>
>>> You can't unconditionally replace uint32(A / uint64(B)) with a 
>>> DIV r32 instruction because if A is big (take 2**62) and B is 
>>> small (take 13) then the quotient will overflow EAX.
>>>
>>> A.
>>>
>>>
>>>
>>> Il giorno martedì 8 novembre 2016 06:18:02 UTC+1, 
>>> ra...@cockroachlabs.com ha scritto:

 Sorry to revive an old thread.  One thing to note is that dividing a 
 64-bit by a 32-bit is much faster than dividing a 64-bit by a 64-bit, at 
 least on recent Intel platforms. Unfortunately there is no valid way to 
 express that kind of calculation in Go..

 Is the compiler/optimizer smart enough to figure out it can do that if 
 you do something like `uint32(a / uint64(b))` where a is `uint64` and b is 
 `uint32`? (the result of that expression can be computed using the 32-bit 
 version of DIV)

 On Saturday, January 19, 2013 at 6:10:34 PM UTC-5, Michael Jones wrote:
>
> Integer division is slow. 
>
> It is the unloved arithmetic operation in CPU design because of its 
> low frequency of occurrence in the instruction stream. It is the one--if 
> you remember childhood schooling--that was "not like the others" in its 
> mechanism: there was lots of guessing using leading digits, trial 
> divisors, 
> and so on. This awkwardness exists even in base 2 (though much less) and 
> means that any division circuit my have to do at least one "fixup" step. 
> (A 
> good design does either zero or one fixup, but that one means more work 
> and 
> plausibly an extra cycle on what is already a long cycle-count activity.)
>
> As one specific example, when adding and subtracting were 1 cycle and 
> multiply was 4, a 32-bit integer division required 19 cycles.
>
>
> On Sat, Jan 19, 2013 at 1:25 PM, minux  wrote:
>
>>
>>
>> On Sun, Jan 20, 2013 at 5:22 AM, Jan Mercl <0xj...@gmail.com> wrote:
>>
>>> On Sat, Jan 19, 2013 at 10:13 PM, Dominik Honnef <
>>> domi...@fork-bomb.org> wrote:
>>>
>>> Cannot reproduce here (Xeon on dont-know-how-much GHz)
>>>
>>> jnml@fsc-r630:~/src/tmp/20130119$ cat a_test.go
>>> package main
>>>
>>> import (
>>> "testing"
>>> )
>>>
>>> func BenchmarkBase(b *testing.B) {
>>> var x int32
>>> for i := 1; i < b.N; i++ {
>>> }
>>> _ = x
>>> }
>>>
>>> func BenchmarkInt(b *testing.B) {
>>> var x int
>>> for i := 1; i < b.N; i++ {
>>> x /= 42
>>> }
>>> _ = x
>>> }
>>>
>> division by a constant should be turned into multiplication by magic 
>> constants
>> by the Go compiler just to avoid the costly divide instruction.
>>
>> you can verify that by 'go tool 6g -S'.
>>
>> -- 
>>  
>>  
>>
>
>
>
> -- 
> Michael T. Jones | Chief Technology Advocate  | m...@google.com |  +1 
> 650-335-5765
>


-- 
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] premature defer in method when using cgo

2016-11-10 Thread iakov . davydov
Hi,
I don't have a minimal example yet, but this looks very suspicious. It 
seems that sometimes defer called before the function finishes, if cgo code 
with callbacks is called in it.

Here's the code:

func (n *NLOPT) Run(iterations int) {
log.Debug("entering Run method")
...
nID := registerObject(n)
defer unregisterObject(nID)
...
// this will call some go function
n.optRes = C.nlopt_optimize(n.gopt, 
(*C.double)(unsafe.Pointer(&x[0])), &maxf)

log.Debug("leaving Run method")
}


Here's what I see in my logs:

entering Run method
register: 1 (0xc82000a900)
... other messages, no "leaving Run method" ...
unregister: 1 (0xc82000a900)
panic: interface conversion: interface {} is nil, not *optimize.NLOPT
(this panic happens because something was prematurely unregistered)

So defer is executed before the method exits.

I tried this in go v1.5 and v1.7, linux64. Sometimes it happens not 
immediately, but after some time.

Are there any special defer rules regarding cgo & callbacks which I do not 
know?

Thanks a lot for your suggestions,
Iakov

-- 
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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer
There are a few problems with the Kubernetes implementation.

The first thing I noticed is that they seem to have copied their code from the 
prometheus go client:

https://github.com/prometheus/client_golang/blob/master/prometheus/http.go#L289 


I don’t know if there was a copyright reassignment, but if not, it looks like 
they failed to honor the prometheus license.

The next problem is that they don’t seem to handle the io.ReaderFrom interface. 
Looking at the commit history of the prometheus code, this is somewhat 
confusing, because they don’t seem to have had a version where this was 
missing. So the Kubernetes developer may have intentionally removed it. It’d be 
curious why.

Last but not least, both the Kubernetes as well as the prometheus 
implementation only address 2 out of the 16 combinations of http.Flusher, 
http.CloseNotifier, http.Hijacker and io.ReaderFrom. Perhaps they determined 
that the go core is only using these 2 combinations. But that’s a bit too 
brittle of an invariant for me to rely on. Therefor my package does the painful 
thing and implements all 16 cases …

Cheers
Felix

> On 10 Nov 2016, at 15:25, Ian Davis  wrote:
> 
> 
> On Thu, Nov 10, 2016, at 02:21 PM, Felix Geisendörfer wrote:
>> Yes, I thought about it :).
>> 
>> Did you read the "Why this package exists” section of the README?
> 
> Yes but obviously not closely enough :)
> 
> Kubernetes takes a hybrid approach:
> 
> https://github.com/kubernetes/kubernetes/blob/master/pkg/apiserver/metrics/metrics.go#L84
>  
> 

-- 
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] Slow 64 bit integer division on amd64

2016-11-10 Thread Michael Jones
A=2^62

B=13

 

A/B = 4611686018427387904/13 

A/B = quotient 354745078340568300 with remainder 4

A/B = (82595524*2^32 + 3964585196) with remainder 4

 

Consider the quotient:

H = Upper 32 bits of 354745078340568300 = 82595524

L = Lower 32 bits of 354745078340568300 = 3964585196

 

Apparently you want L.

 

uint32(uint64(354745078340568300)) = 3964585196

 

The overflow condition is that the quotient is not representable in 32 bits. 
Reference:

http://stackoverflow.com/questions/22596059/problems-dividing-64-bits-in-x86-assembly

 

 

From:  on behalf of 
Date: Thursday, November 10, 2016 at 6:05 AM
To: golang-nuts 
Cc: , <0xj...@gmail.com>, , 

Subject: Re: [go-nuts] Slow 64 bit integer division on amd64

 

n your example, A=2^62 and B=13`, `uint32(A / uint64(B))` is (2^62 / 13) % 2^32 
which I thought is exactly the result of DIV r32.

-- 
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] why "iota"?

2016-11-10 Thread Michael Jones
“…on our math high school courses.” 

Which I imagine are like my college math courses!


-Original Message-
From:  on behalf of Konstantin Khomoutov 

Date: Thursday, November 10, 2016 at 4:09 AM
To: Dan Kortschak 
Cc: Marvin Renich , golang-nuts 
Subject: Re: [go-nuts] why "iota"?

On Thu, 10 Nov 2016 10:27:49 +1030
Dan Kortschak  wrote:

> On Wed, 2016-11-09 at 09:30 -0500, Marvin Renich wrote:
> > Iota is pronounced eye-OH-tuh.
>
> Or yoh-ta (like Yoda, but with s/d/t/) if not in America.
>

I concur that here in Russia we taught to spell it yoh-ta on our math
high school courses.

-- 
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] why "iota"?

2016-11-10 Thread Rob Pike
You had math in high school?

-rob


On Thu, Nov 10, 2016 at 6:43 AM, Michael Jones 
wrote:

> “…on our math high school courses.”
>
> Which I imagine are like my college math courses!
>
>
> -Original Message-
> From:  on behalf of Konstantin Khomoutov <
> flatw...@users.sourceforge.net>
> Date: Thursday, November 10, 2016 at 4:09 AM
> To: Dan Kortschak 
> Cc: Marvin Renich , golang-nuts <
> golang-nuts@googlegroups.com>
> Subject: Re: [go-nuts] why "iota"?
>
> On Thu, 10 Nov 2016 10:27:49 +1030
> Dan Kortschak  wrote:
>
> > On Wed, 2016-11-09 at 09:30 -0500, Marvin Renich wrote:
> > > Iota is pronounced eye-OH-tuh.
> >
> > Or yoh-ta (like Yoda, but with s/d/t/) if not in America.
> >
>
> I concur that here in Russia we taught to spell it yoh-ta on our math
> high school courses.
>
> --
> 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.
>

-- 
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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Ian Davis
Out of interest, do you have any examples of packages that perform a
type check to reject an operation with a response writer? Your
implementation is complex purely to address this scenario.

I would think that 99+% of all type checks are to determine whether the
supplied object provides additional functionality that can be used. I'm
struggling to think of a situation where you would type check for the
Flush method and then refuse to use the main ResponseWriter methods if
it were a Flusher.


On Thu, Nov 10, 2016, at 02:37 PM, Felix Geisendörfer wrote:
> There are a few problems with the Kubernetes implementation.
>
> The first thing I noticed is that they seem to have copied their code
> from the prometheus go client:
>
> https://github.com/prometheus/client_golang/blob/master/prometheus/http.go#L289
>
> I don’t know if there was a copyright reassignment, but if not, it
> looks like they failed to honor the prometheus license.
>
> The next problem is that they don’t seem to handle the io.ReaderFrom
> interface. Looking at the commit history of the prometheus code, this
> is somewhat confusing, because they don’t seem to have had a version
> where this was missing. So the Kubernetes developer may have
> intentionally removed it. It’d be curious why.
>
> Last but not least, both the Kubernetes as well as the prometheus
> implementation only address 2 out of the 16 combinations of
> http.Flusher, http.CloseNotifier, http.Hijacker and io.ReaderFrom.
> Perhaps they determined that the go core is only using these 2
> combinations. But that’s a bit too brittle of an invariant for me to
> rely on. Therefor my package does the painful thing and implements all
> 16 cases …
>
> Cheers
> Felix
>
>> On 10 Nov 2016, at 15:25, Ian Davis  wrote:
>>
>>
>> On Thu, Nov 10, 2016, at 02:21 PM, Felix Geisendörfer wrote:
>>> Yes, I thought about it :).
>>>
>>> Did you read the "Why this package exists” section of the README?
>>
>> Yes but obviously not closely enough :)
>>
>> Kubernetes takes a hybrid approach:
>>
>> https://github.com/kubernetes/kubernetes/blob/master/pkg/apiserver/metrics/metrics.go#L84

-- 
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 generate "pipelines"

2016-11-10 Thread Rob Pike
Offhand:

You would need to write the programs go generate is calling to be
idempotent, and have the second one exit quietly if the first hasn't run.
You would then either run go generate twice or have the first program run
go generate once it had completed.

Not pretty but it does seem like a rare case. To be honest, I'd probably
use a Makefile instead of go generate.

-rob


On Thu, Nov 10, 2016 at 2:37 AM, Paul Jolly  wrote:

> Hi - wondering whether anyone knows of any tooling that helps with
> "pipelines" (probably not a great choice of phrase) of go generate-able
> code.
>
> Specifically the case where the output of one go generate program is code
> which is itself go generate-able (and hence requires another invocation of
> go generate)
>
> There are various strategies I can think of for handling this situation,
> but wanted to check if there was prior art out there before starting
> something home-baked.
>
> Thanks,
>
>
> Paul
>
> --
> 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: go generate "pipelines"

2016-11-10 Thread Tieson Molly
Not exactly, but I was looking at goa, and the goagen generates some code 
that you can then run go generate against.

On Thursday, November 10, 2016 at 5:37:39 AM UTC-5, Paul Jolly wrote:
>
> Hi - wondering whether anyone knows of any tooling that helps with 
> "pipelines" (probably not a great choice of phrase) of go generate-able 
> code. 
>
> Specifically the case where the output of one go generate program is code 
> which is itself go generate-able (and hence requires another invocation of 
> go generate)
>
> There are various strategies I can think of for handling this situation, 
> but wanted to check if there was prior art out there before starting 
> something home-baked.
>
> Thanks,
>
>
> Paul
>

-- 
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] premature defer in method when using cgo

2016-11-10 Thread Jan Mercl
On Thu, Nov 10, 2016 at 3:31 PM  wrote:

> So defer is executed before the method exits.

Does log.Debug flush its output before returning?

-- 

-j

-- 
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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer

> On 10 Nov 2016, at 15:59, Ian Davis  wrote:
> 
> Out of interest, do you have any examples of packages that perform a type 
> check to reject an operation with a response writer? Your implementation is 
> complex purely to address this scenario.

No, that was a bogus example.

However, I do have an application that will misbehave if CloseNotify is not 
implemented or not implemented properly.

And I think it’s also easy to imagine that it’s downright impossible to fake 
http.Hijacker if the underlaying ResponseWriter doesn’t support it.

> I would think that 99+% of all type checks are to determine whether the 
> supplied object provides additional functionality that can be used. I'm 
> struggling to think of a situation where you would type check for the Flush 
> method and then refuse to use the main ResponseWriter methods if it were a 
> Flusher.

I agree. But verifying if you’re part of the 99% or 1% may be a very complex 
task, especially when using 3rd party http related packages.

So why would I want to worry about this invariant holding for a large amount of 
source code, if I can fix the problem with a comparably much smaller amount of 
boilerplate?

Cheers
Felix

> 
> 
> On Thu, Nov 10, 2016, at 02:37 PM, Felix Geisendörfer wrote:
>> There are a few problems with the Kubernetes implementation.
>> 
>> The first thing I noticed is that they seem to have copied their code from 
>> the prometheus go client:
>> 
>> https://github.com/prometheus/client_golang/blob/master/prometheus/http.go#L289
>>  
>> 
>> 
>> I don’t know if there was a copyright reassignment, but if not, it looks 
>> like they failed to honor the prometheus license.
>> 
>> The next problem is that they don’t seem to handle the io.Reader>From 
>> interface. Looking at the commit history of the prometheus code, this is 
>> somewhat confusing, because they don’t seem to have had a version where this 
>> was missing. So the Kubernetes developer may have intentionally removed it. 
>> It’d be curious why.
>> 
>> Last but not least, both the Kubernetes as well as the prometheus 
>> implementation only address 2 out of the 16 combinations of http.Flusher, 
>> http.CloseNotifier, http.Hijacker and io.ReaderFrom. Perhaps they determined 
>> that the go core is only using these 2 combinations. But that’s a bit too 
>> brittle of an invariant for me to rely on. Therefor my package does the 
>> painful thing and implements all 16 cases …
>> 
>> Cheers
>> Felix
>> 
>>> On 10 Nov 2016, at 15:25, Ian Davis >> > wrote:
>>> 
>>> 
>>> On Thu, Nov 10, 2016, at 02:21 PM, Felix Geisendörfer wrote:
 Yes, I thought about it :).
 
 Did you read the "Why this package exists” section of the README?
>>> 
>>> Yes but obviously not closely enough :)
>>> 
>>> Kubernetes takes a hybrid approach:
>>> 
>>> https://github.com/kubernetes/kubernetes/blob/master/pkg/apiserver/metrics/metrics.go#L84
>>>  
>>> 
> 

-- 
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] why "iota"?

2016-11-10 Thread Konstantin Khomoutov
On Thu, 10 Nov 2016 06:43:09 -0800
Michael Jones  wrote:

> “…on our math high school courses.” 
> 
> Which I imagine are like my college math courses!

Oh, yes, I meant college; silly me ;-)

The problem is that we have somewhat incompatible denominations for
these education-related terms, and what americans call "high school" is
called with what translates like "middle school" here.

-- 
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 parser

2016-11-10 Thread Sergio Hunter
Thanks so much for your answer. 
I'll try to explain what I need. I have a field "data",inside field has 
compress rows and text data(json), I need decompress data, but my code 
begins to unpack the file to text and compiler generates an error.
The logic is this: It reads "data" of the database, do "json.NewDecoder", 
if "json.NewDecoder" did not work - will "err", then if there are "err" is 
necessary to decompress and do again "json.NewDecoder". 
I hope you are understand me, thanks.

четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
написал:
>
> I'm also not sure what you are trying to do.  However, I think I can see a 
> bug in your code.
>
> First you run a database query to get a list of values from a field called 
> data.  This could produce up to 10 values.
>
> Next you have a loop which runs through the values and discards them.  At 
> the end of the loop, you have the data field from the last record, and you 
> have thrown away all the others.  Is this what you want?
>
> Finally, you unzip the last data field.
>
> So if your table contains 100 records, you will get 10 of them, throw away 
> the first 9 records and unzip the data from the last one.
>
> I hope this helps.
>
>

-- 
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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Ian Davis
On Thu, Nov 10, 2016, at 03:21 PM, Felix Geisendörfer wrote:
>
>> I would think that 99+% of all type checks are to determine whether
>> the supplied object provides additional functionality that can be
>> used. I'm struggling to think of a situation where you would type
>> check for the Flush method and then refuse to use the main
>> ResponseWriter methods if it were a Flusher.
>
> I agree. But verifying if you’re part of the 99% or 1% may be a very
> complex task, especially when using 3rd party http related packages.
>
> So why would I want to worry about this invariant holding for a large
> amount of source code, if I can fix the problem with a comparably much
> smaller amount of boilerplate?

You can't in the general case. You cover the interfaces that you
currently know about but you don't know what other interfaces people
are relying on. Sipporting those becomes a combinatorial problem of
whack-a-mole.

-- 
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 regexp replace missing functionalities?

2016-11-10 Thread Tong Sun
While trying to solve the following problem, it seems that Go regexp
replacement is missing an important functionality -- able to do
full-fledged replacing with user defined functions.

- I know that "ReplaceAllStringFunc" is designed to do that, however, it is
missing an important aspect of regexp replacement -- the capability of
directly handling matched groups within it.
- I know that "expand" is able to handle matched groups within it, but the
problem is that it is ignoring anything else apart from the replacing part.

So, it seems that Go regexp replacement lacks the ability of direct groups
handling functionality. I know there are ways to workaround it, but the
problem is that they are just workarounds, and, different people
have different workarounds. I.e., it is chaotic without a canonical way of
doing it.

To illustrate, let me use a simpler example than the following. So here is
the input and output that can demonstrate the problem:

INPUT:

We need to increase the precisions. Here is the plan:

- crc8; Crc12

- aes16; Aes32

- CRC32 and then rename it to just Crc


OUTPUT:

We need to increase the precisions. Here is the plan:

- from crc8 to crc12 (8 * 1.5 = 12); from Crc12 to Crc18 (12 * 1.5 = 18)
- from aes16 to aes24 (16 * 1.5 = 24); from Aes32 to Aes48 (32 * 1.5 = 48)
- from CRC32 to CRC48 (32 * 1.5 = 48) and then rename it to just Crc


To get the output with Perl:

perl -pe 's((crc|aes)(\d+))($want=$2; $want+=$2/2; "from $1$2 to $1$want
($2 * 1.5 = $want)")ige'


I.e., Perl can use the matched groups in the user defined replace function
without haggle. Can Go do that *without haggle*?

Thanks

On Sun, Nov 6, 2016 at 5:35 PM, Tong Sun wrote:

>
>
> On Saturday, November 5, 2016 at 3:51:55 PM UTC-4, Tong Sun wrote:
>>
>>
>> On Saturday, November 5, 2016 at 3:42:27 PM UTC-4, Tong Sun wrote:
>>>
>>>
>>> On Sat, Nov 5, 2016 at 12:26 PM, Sam Whited  wrote:
>>>
 On Fri, Nov 4, 2016 at 4:32 PM, Tong Sun wrote:
 > How to beautify a given XML string in GO?...
>>>
>>> I guess such thing doesn't exist, but let me ask away anyway -- the
>>> following is exactly what I was looking for, couldn't express better than
>>> his:
>>>
>>> from http://stackoverflow.com/questions/21117161:
>>>
>>> I like this solution, but am still in search of a Golang XML
 formatter/prettyprinter that doesn't rewrite the document (other than
 formatting whitespace). Marshalling or using the Encoder will change
 namespace declarations. For example an element like "" will
 be translated to something like '' which
 seems harmless enough except when the intent is to not alter the xml other
 than formatting. – James McGill
  Nov 12 '15
 
>>>
>>>
>>> Using Sam's above code as an example,
>>>
>>> https://play.golang.org/p/JUqQY3WpW5
>>>
>>> The above code format the following XML
>>>
>>> http://schemas.
>>> xmlsoap.org/soap/envelope/"
>>>   xmlns:ns="http://example.com/ns";>
>>>
>>>
>>>  
>>>   
>>>123
>>>John Brown
>>>   
>>>  
>>>
>>> 
>>>
>>>
>>> into this:
>>>
>>> http://schemas.xmlsoap.org/soap/envelope/";
>>> xmlns:_xmlns="xmlns" _xmlns:soapenv="http://schemas
>>> .xmlsoap.org/soap/envelope/" _xmlns:ns="http://example.com/ns";>
>>>  http://schemas.xmlsoap.org/soap/envelope/";>
>>>  http://schemas.xmlsoap.org/soap/envelope/";>
>>>   http://example.com/ns";>
>>>http://example.com/ns";>
>>> http://example.com/ns";>123
>>> http://example.com/ns"; type="NCHZ">John Brown
>>>
>>>   
>>>  
>>> 
>>>
>>>
>>> I know they are the same in syntax, however they look totally different.
>>>
>>> Any way (e.g., to tweak encoding/xml) to make the beautified string look
>>> closer to the original?
>>>
>>
>> FTR, trying to look into that direction myself, ..., I *got it working*.
>> After all, XML is much more structured than HTML. Here is what it was
>> previously:
>>
>
> $ echo 'http://schemas.xmlsoap.org/soap/envelope/
> xmlns:_xmlns=xmlns _xmlns:soapenv=http://schemas.
> xmlsoap.org/soap/envelope/ _xmlns:ns=http://example.com/ns> http://schemas.xmlsoap.org/soap/envelope/> http://schemas.xmlsoap.org/soap/envelope/> http://example.com/ns>http://example.com/ns> http://example.com/ns>123http://example.com/ns
> type=NCHZ>John Brown' |
> perl -pe 's/(?<=>)\s+(?=<)//g; s(<(/?)([^/>]+)(/?)>\s*(?=( ))?)($indent+=$3?0:$1?-1:1;"<$1$2$3>".($1&&($4 eq"  "x$indent):$4?"\n".("  "x$indent):""))ge'
> http://schemas.xmlsoap.org/soap/envelope/ xmlns:_xmlns=
> xmlns _xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ _xmlns:ns=
> http://example.com/ns>http://schemas.xmlsoap.
> org/soap/envelope/>
> http://schemas.xmlsoap.org/soap/envelope/> http://example.com/ns>http://example.com/ns> http://example.com/ns>123
> http://example.com/ns type=NCHZ>John Brown
> 
> 
> 
> 
>
>
>
> After simplified the alg

Re: [go-nuts] why "iota"?

2016-11-10 Thread Michael Jones
…I was not correcting you. I was saying that the whole world appreciates the 
strength of Russian math education as consistently demonstrated in the 
International Mathematical Olympiad. (This is the Olympics that excites me, the 
place for people who can wrestle with exponential generating functions as ably 
as people in the other Olympics can throw a stick or kick a ball.)

поздравления

-Original Message-
From: Konstantin Khomoutov 
Date: Thursday, November 10, 2016 at 7:28 AM
To: Michael Jones 
Cc: Konstantin Khomoutov , Dan Kortschak 
, Marvin Renich , golang-nuts 

Subject: Re: [go-nuts] why "iota"?

On Thu, 10 Nov 2016 06:43:09 -0800
Michael Jones  wrote:

> “…on our math high school courses.” 
> 
> Which I imagine are like my college math courses!

Oh, yes, I meant college; silly me ;-)

The problem is that we have somewhat incompatible denominations for
these education-related terms, and what americans call "high school" is
called with what translates like "middle school" here.



-- 
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: Concurrent map error in net/http/trasport

2016-11-10 Thread adonovan via golang-nuts
On Thursday, 10 November 2016 04:09:29 UTC-5, James Pettyjohn wrote:
>
> I ran into this on go 1.6.2 amd64, seems unlikely this is a core issue and 
> I need to look else where in the project but has anyone seen this before?
>
> fatal error: concurrent map read and map write
>
> goroutine 21619 [running]:
> runtime.throw(0xfefc00, 0x21)
> /usr/local/go/src/runtime/panic.go:547 +0x90 fp=0xc822727ac0 
> sp=0xc822727aa8
> runtime.mapaccess1(0xca4a00, 0xc828346120, 0xc822727c58, 0x1931c00)
> /usr/local/go/src/runtime/hashmap.go:289 +0x5a fp=0xc822727b08 
> sp=0xc822727ac0
> net/http.(*Transport).tryPutIdleConn(0xc822c00b40, 0xc82181fc70, 0x0, 0x0)
> /usr/local/go/src/net/http/transport.go:562 +0x41e fp=0xc822727c90 
> sp=0xc822727b08
> net/http.(*persistConn).readLoop.func2(0xc82181fc70)
> /usr/local/go/src/net/http/transport.go:1053 +0x32 fp=0xc822727cd0 
> sp=0xc822727c90
> net/http.(*persistConn).readLoop(0xc82181fc70)
> /usr/local/go/src/net/http/transport.go:1189 +0xc5d 
> fp=0xc822727fa8 sp=0xc822727cd0
> runtime.goexit()
> /usr/local/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc822727fb0 
> sp=0xc822727fa8
> created by net/http.(*Transport).dialConn
> /usr/local/go/src/net/http/transport.go:857 +0x10a6
>


The locks surrounding idleConn map all look locally fine. Is it possible 
your application has made a (shallow) copy of an http.Transport?  The old 
and new copies would share the same idleConn map "guarded" by different 
idleMu mutexes.



-- 
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 parser

2016-11-10 Thread pierre . curto
Ok, then something along those lines:
https://play.golang.org/p/dMPQIrEdNN

Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :
>
> Thanks so much for your answer. 
> I'll try to explain what I need. I have a field "data",inside field has 
> compress rows and text data(json), I need decompress data, but my code 
> begins to unpack the file to text and compiler generates an error.
> The logic is this: It reads "data" of the database, do "json.NewDecoder", 
> if "json.NewDecoder" did not work - will "err", then if there are "err" is 
> necessary to decompress and do again "json.NewDecoder". 
> I hope you are understand me, thanks.
>
> четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
> написал:
>>
>> I'm also not sure what you are trying to do.  However, I think I can see 
>> a bug in your code.
>>
>> First you run a database query to get a list of values from a field 
>> called data.  This could produce up to 10 values.
>>
>> Next you have a loop which runs through the values and discards them.  At 
>> the end of the loop, you have the data field from the last record, and you 
>> have thrown away all the others.  Is this what you want?
>>
>> Finally, you unzip the last data field.
>>
>> So if your table contains 100 records, you will get 10 of them, throw 
>> away the first 9 records and unzip the data from the last one.
>>
>> I hope this helps.
>>
>>

-- 
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: [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Tong Sun
That's very interesting Felix. Can it handle https requests as well? 


On Thursday, November 10, 2016 at 6:09:32 AM UTC-5, Felix Geisendoerfer 
wrote:
>
> Hi all,
>
> while working on instrumenting my application, I ran into the fact that 
> capturing metrics such as status codes from my own http.Handlers is 
> surprisingly difficult to get right.
>
> Therefor I created a package that hopefully avoids most of the common 
> pitfalls. 
>
> https://github.com/felixge/httpsnoop
>
> I would love for net/http experts to take a look at the "Why this package 
> exists" section of the README, as well as the horrible hack required to 
> make things work:
>
> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163
>
> Please let me know if you have suggestions for simpler approaches and/or 
> spot any bugs in my implementation.
>
> Thanks a lot!
> Felix Geisendörfer
>

-- 
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] [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer

> On 10 Nov 2016, at 16:44, Ian Davis  wrote:
> 
> You can't in the general case. You cover the interfaces that you currently 
> know about but you don't know what other interfaces people are relying on. 
> Sipporting those becomes a combinatorial problem of whack-a-mole.

I think Go 1.7 allows for the general case to be solved using reflect.StructOf.

But I haven’t tried it yet, because I can’t use 1.7 until my new MBP arrives 
next week :(.

In the meantime, supporting 16 / N cases still seems better than supporting 2 / 
N cases. And to my knowledge there exists no alternative to httpsnoop right now 
that isn’t tied to a particular logging/metrics library.

Cheers
Felix

[1] https://github.com/golang/go/issues/16726 


-- 
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: [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer
Hi Tong,

the README example shows logging request related information (method, url) in 
addition to the response related stuff.

Most of the request related information is easy to get directly from the 
request object, so I didn’t implement any special support for that yet.

That being said, I could imagine adding a `Read` metrics field for the number 
of bytes read from the request’s body.

What sort of metrics did you have in mind?

Cheers
Felix

> On 10 Nov 2016, at 16:55, Tong Sun  wrote:
> 
> That's very interesting Felix. Can it handle https requests as well? 
> 
> 
> On Thursday, November 10, 2016 at 6:09:32 AM UTC-5, Felix Geisendoerfer wrote:
> Hi all,
> 
> while working on instrumenting my application, I ran into the fact that 
> capturing metrics such as status codes from my own http.Handlers is 
> surprisingly difficult to get right.
> 
> Therefor I created a package that hopefully avoids most of the common 
> pitfalls. 
> 
> https://github.com/felixge/httpsnoop 
> 
> I would love for net/http experts to take a look at the "Why this package 
> exists" section of the README, as well as the horrible hack required to make 
> things work:
> 
> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163 
> 
> 
> Please let me know if you have suggestions for simpler approaches and/or spot 
> any bugs in my implementation.
> 
> Thanks a lot!
> Felix Geisendörfer
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/-I5IZgJosYE/unsubscribe 
> .
> To unsubscribe from this group and all its topics, 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] Re: [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer
Tong, I may have misread your e-mail. I missed the “s” in http(s).

I don’t see anything that would be special about http requests, so they should 
just work.

Cheers
Felix

> On 10 Nov 2016, at 17:02, Felix Geisendörfer  wrote:
> 
> Hi Tong,
> 
> the README example shows logging request related information (method, url) in 
> addition to the response related stuff.
> 
> Most of the request related information is easy to get directly from the 
> request object, so I didn’t implement any special support for that yet.
> 
> That being said, I could imagine adding a `Read` metrics field for the number 
> of bytes read from the request’s body.
> 
> What sort of metrics did you have in mind?
> 
> Cheers
> Felix
> 
>> On 10 Nov 2016, at 16:55, Tong Sun > > wrote:
>> 
>> That's very interesting Felix. Can it handle https requests as well? 
>> 
>> 
>> On Thursday, November 10, 2016 at 6:09:32 AM UTC-5, Felix Geisendoerfer 
>> wrote:
>> Hi all,
>> 
>> while working on instrumenting my application, I ran into the fact that 
>> capturing metrics such as status codes from my own http.Handlers is 
>> surprisingly difficult to get right.
>> 
>> Therefor I created a package that hopefully avoids most of the common 
>> pitfalls. 
>> 
>> https://github.com/felixge/httpsnoop 
>> 
>> I would love for net/http experts to take a look at the "Why this package 
>> exists" section of the README, as well as the horrible hack required to make 
>> things work:
>> 
>> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163 
>> 
>> 
>> Please let me know if you have suggestions for simpler approaches and/or 
>> spot any bugs in my implementation.
>> 
>> Thanks a lot!
>> Felix Geisendörfer
>> 
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/golang-nuts/-I5IZgJosYE/unsubscribe 
>> .
>> To unsubscribe from this group and all its topics, 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] Re: [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Tong Sun
Yep, that's what I meant. Thanks.

On Thu, Nov 10, 2016 at 11:04 AM, Felix Geisendörfer 
wrote:

> Tong, I may have misread your e-mail. I missed the “s” in http(s).
>
> I don’t see anything that would be special about http requests, so they
> should just work.
>
> Cheers
> Felix
>
> On 10 Nov 2016, at 17:02, Felix Geisendörfer  wrote:
>
> Hi Tong,
>
> the README example shows logging request related information (method, url)
> in addition to the response related stuff.
>
> Most of the request related information is easy to get directly from the
> request object, so I didn’t implement any special support for that yet.
>
> That being said, I could imagine adding a `Read` metrics field for the
> number of bytes read from the request’s body.
>
> What sort of metrics did you have in mind?
>
> Cheers
> Felix
>
> On 10 Nov 2016, at 16:55, Tong Sun  wrote:
>
> That's very interesting Felix. Can it handle https requests as well?
>
>
> On Thursday, November 10, 2016 at 6:09:32 AM UTC-5, Felix Geisendoerfer
> wrote:
>>
>> Hi all,
>>
>> while working on instrumenting my application, I ran into the fact that
>> capturing metrics such as status codes from my own http.Handlers is
>> surprisingly difficult to get right.
>>
>> Therefor I created a package that hopefully avoids most of the common
>> pitfalls.
>>
>> https://github.com/felixge/httpsnoop
>>
>> I would love for net/http experts to take a look at the "Why this package
>> exists" section of the README, as well as the horrible hack required to
>> make things work:
>>
>> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163
>>
>> Please let me know if you have suggestions for simpler approaches and/or
>> spot any bugs in my implementation.
>>
>> Thanks a lot!
>> Felix Geisendörfer
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/-I5IZgJosYE/unsubscribe.
> To unsubscribe from this group and all its topics, 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: JSON parser

2016-11-10 Thread Sergio Hunter
The compiler generates an error

Test.go:71: undefined: o
Test.go:85: cannot use nil as type Object in return argument





четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь pierre...@gmail.com 
написал:
>
> Ok, then something along those lines:
> https://play.golang.org/p/dMPQIrEdNN
>
> Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :
>>
>> Thanks so much for your answer. 
>> I'll try to explain what I need. I have a field "data",inside field has 
>> compress rows and text data(json), I need decompress data, but my code 
>> begins to unpack the file to text and compiler generates an error.
>> The logic is this: It reads "data" of the database, do "json.NewDecoder", 
>> if "json.NewDecoder" did not work - will "err", then if there are "err" is 
>> necessary to decompress and do again "json.NewDecoder". 
>> I hope you are understand me, thanks.
>>
>> четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
>> написал:
>>>
>>> I'm also not sure what you are trying to do.  However, I think I can see 
>>> a bug in your code.
>>>
>>> First you run a database query to get a list of values from a field 
>>> called data.  This could produce up to 10 values.
>>>
>>> Next you have a loop which runs through the values and discards them. 
>>>  At the end of the loop, you have the data field from the last record, and 
>>> you have thrown away all the others.  Is this what you want?
>>>
>>> Finally, you unzip the last data field.
>>>
>>> So if your table contains 100 records, you will get 10 of them, throw 
>>> away the first 9 records and unzip the data from the last one.
>>>
>>> I hope this helps.
>>>
>>>

-- 
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 generate "pipelines"

2016-11-10 Thread Pietro Gagliardi
Why not just run all those generate commands in a single go generate call, such 
as a shell script or a go run?
> On Nov 10, 2016, at 9:53 AM, Rob Pike  wrote:
> 
> Offhand:
> 
> You would need to write the programs go generate is calling to be idempotent, 
> and have the second one exit quietly if the first hasn't run. You would then 
> either run go generate twice or have the first program run go generate once 
> it had completed.
> 
> Not pretty but it does seem like a rare case. To be honest, I'd probably use 
> a Makefile instead of go generate.
> 
> -rob
> 
> 
> On Thu, Nov 10, 2016 at 2:37 AM, Paul Jolly  > wrote:
> Hi - wondering whether anyone knows of any tooling that helps with 
> "pipelines" (probably not a great choice of phrase) of go generate-able code. 
> 
> Specifically the case where the output of one go generate program is code 
> which is itself go generate-able (and hence requires another invocation of go 
> generate)
> 
> There are various strategies I can think of for handling this situation, but 
> wanted to check if there was prior art out there before starting something 
> home-baked.
> 
> Thanks,
> 
> 
> Paul
> 
> -- 
> 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 
> .

-- 
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] premature defer in method when using cgo

2016-11-10 Thread Ian Lance Taylor
On Thu, Nov 10, 2016 at 3:18 AM,   wrote:
>
> I don't have a minimal example yet, but this looks very suspicious. It seems
> that sometimes defer called before the function finishes, if cgo code with
> callbacks is called in it.
>
> Here's the code:
>
> func (n *NLOPT) Run(iterations int) {
> log.Debug("entering Run method")
> ...
> nID := registerObject(n)
> defer unregisterObject(nID)
> ...
> // this will call some go function
> n.optRes = C.nlopt_optimize(n.gopt,
> (*C.double)(unsafe.Pointer(&x[0])), &maxf)
> 
> log.Debug("leaving Run method")
> }
>
>
> Here's what I see in my logs:
>
> entering Run method
> register: 1 (0xc82000a900)
> ... other messages, no "leaving Run method" ...
> unregister: 1 (0xc82000a900)
> panic: interface conversion: interface {} is nil, not *optimize.NLOPT
> (this panic happens because something was prematurely unregistered)
>
> So defer is executed before the method exits.
>
> I tried this in go v1.5 and v1.7, linux64. Sometimes it happens not
> immediately, but after some time.
>
> Are there any special defer rules regarding cgo & callbacks which I do not
> know?

I doubt it.  Please show us a minimal example.

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] premature defer in method when using cgo

2016-11-10 Thread iakov . davydov
Hi,
As far as I understand, os.Stdout & os.Stderr are not buffered.
log.Debug writes to stderr. I replaced log.Debug with println, the result 
is the same.
Cheers,
Iakov

P.S. Struggling with creating a minimal example; the results is not very 
stable. Will put it here if I will manage.

On Thursday, November 10, 2016 at 4:19:35 PM UTC+1, Jan Mercl wrote:
>
> On Thu, Nov 10, 2016 at 3:31 PM > wrote:
>
> > So defer is executed before the method exits.
>
> Does log.Debug flush its output before returning?
>
> -- 
>
> -j
>

-- 
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 parser

2016-11-10 Thread pierre . curto
Sorry, I did not test it. This one passes the playground build (up to the 
mysql driver not being found):
https://play.golang.org/p/_WfTMOd-s6

Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit :
>
> The compiler generates an error
>
> Test.go:71: undefined: o
> Test.go:85: cannot use nil as type Object in return argument
>
>
>
>
>
> четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь 
> pierre...@gmail.com написал:
>>
>> Ok, then something along those lines:
>> https://play.golang.org/p/dMPQIrEdNN
>>
>> Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :
>>>
>>> Thanks so much for your answer. 
>>> I'll try to explain what I need. I have a field "data",inside field has 
>>> compress rows and text data(json), I need decompress data, but my code 
>>> begins to unpack the file to text and compiler generates an error.
>>> The logic is this: It reads "data" of the database, do 
>>> "json.NewDecoder", if "json.NewDecoder" did not work - will "err", then if 
>>> there are "err" is necessary to decompress and do again "json.NewDecoder". 
>>> I hope you are understand me, thanks.
>>>
>>> четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
>>> написал:

 I'm also not sure what you are trying to do.  However, I think I can 
 see a bug in your code.

 First you run a database query to get a list of values from a field 
 called data.  This could produce up to 10 values.

 Next you have a loop which runs through the values and discards them. 
  At the end of the loop, you have the data field from the last record, and 
 you have thrown away all the others.  Is this what you want?

 Finally, you unzip the last data field.

 So if your table contains 100 records, you will get 10 of them, throw 
 away the first 9 records and unzip the data from the last one.

 I hope this helps.



-- 
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 parser

2016-11-10 Thread Sergio Hunter
Thanks for your help. 
Do you know what it means? 
2016/11/10 18:46:21 invalid character '\u0085' looking for beginning of 
value
exit status 1


четверг, 10 ноября 2016 г., 18:32:40 UTC+2 пользователь pierre...@gmail.com 
написал:
>
> Sorry, I did not test it. This one passes the playground build (up to the 
> mysql driver not being found):
> https://play.golang.org/p/_WfTMOd-s6
>
> Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit :
>>
>> The compiler generates an error
>>
>> Test.go:71: undefined: o
>> Test.go:85: cannot use nil as type Object in return argument
>>
>>
>>
>>
>>
>> четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь 
>> pierre...@gmail.com написал:
>>>
>>> Ok, then something along those lines:
>>> https://play.golang.org/p/dMPQIrEdNN
>>>
>>> Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :

 Thanks so much for your answer. 
 I'll try to explain what I need. I have a field "data",inside field has 
 compress rows and text data(json), I need decompress data, but my code 
 begins to unpack the file to text and compiler generates an error.
 The logic is this: It reads "data" of the database, do 
 "json.NewDecoder", if "json.NewDecoder" did not work - will "err", then if 
 there are "err" is necessary to decompress and do again "json.NewDecoder". 
 I hope you are understand me, thanks.

 четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
 написал:
>
> I'm also not sure what you are trying to do.  However, I think I can 
> see a bug in your code.
>
> First you run a database query to get a list of values from a field 
> called data.  This could produce up to 10 values.
>
> Next you have a loop which runs through the values and discards them. 
>  At the end of the loop, you have the data field from the last record, 
> and 
> you have thrown away all the others.  Is this what you want?
>
> Finally, you unzip the last data field.
>
> So if your table contains 100 records, you will get 10 of them, throw 
> away the first 9 records and unzip the data from the last one.
>
> I hope this helps.
>
>

-- 
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 parser

2016-11-10 Thread pierre . curto
We will get there but is is hard hitting your target when shooting in the 
dark :).

Remove white spaces:
https://play.golang.org/p/_LktUPDhYW

Le jeudi 10 novembre 2016 17:52:21 UTC+1, Sergio Hunter a écrit :
>
> Thanks for your help. 
> Do you know what it means? 
> 2016/11/10 18:46:21 invalid character '\u0085' looking for beginning of 
> value
> exit status 1
>
>
> четверг, 10 ноября 2016 г., 18:32:40 UTC+2 пользователь 
> pierre...@gmail.com написал:
>>
>> Sorry, I did not test it. This one passes the playground build (up to the 
>> mysql driver not being found):
>> https://play.golang.org/p/_WfTMOd-s6
>>
>> Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit :
>>>
>>> The compiler generates an error
>>>
>>> Test.go:71: undefined: o
>>> Test.go:85: cannot use nil as type Object in return argument
>>>
>>>
>>>
>>>
>>>
>>> четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь 
>>> pierre...@gmail.com написал:

 Ok, then something along those lines:
 https://play.golang.org/p/dMPQIrEdNN

 Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :
>
> Thanks so much for your answer. 
> I'll try to explain what I need. I have a field "data",inside field 
> has compress rows and text data(json), I need decompress data, but my 
> code 
> begins to unpack the file to text and compiler generates an error.
> The logic is this: It reads "data" of the database, do 
> "json.NewDecoder", if "json.NewDecoder" did not work - will "err", then 
> if 
> there are "err" is necessary to decompress and do again 
> "json.NewDecoder". 
> I hope you are understand me, thanks.
>
> четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
> написал:
>>
>> I'm also not sure what you are trying to do.  However, I think I can 
>> see a bug in your code.
>>
>> First you run a database query to get a list of values from a field 
>> called data.  This could produce up to 10 values.
>>
>> Next you have a loop which runs through the values and discards them. 
>>  At the end of the loop, you have the data field from the last record, 
>> and 
>> you have thrown away all the others.  Is this what you want?
>>
>> Finally, you unzip the last data field.
>>
>> So if your table contains 100 records, you will get 10 of them, throw 
>> away the first 9 records and unzip the data from the last one.
>>
>> I hope this helps.
>>
>>

-- 
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: premature defer in method when using cgo

2016-11-10 Thread iakov . davydov
e been violating cgo rules by passing Go pointer to an integer to the C 
code for storage.

C.nlopt_set_max_objective(n.gopt, 
(C.nlopt_func)(unsafe.Pointer(C.callback_adaptor)), unsafe.Pointer(&nID))

Now I do it like this instead:

C.nlopt_set_max_objective(n.gopt, 
(C.nlopt_func)(unsafe.Pointer(C.callback_adaptor)), 
unsafe.Pointer(uintptr(nID)))

And the problem is gone.
Thanks for your help,
Iakov

On Thursday, November 10, 2016 at 3:32:02 PM UTC+1, iakov@gmail.com 
wrote:
>
> Hi,
> I don't have a minimal example yet, but this looks very suspicious. It 
> seems that sometimes defer called before the function finishes, if cgo code 
> with callbacks is called in it.
>
> Here's the code:
>
> func (n *NLOPT) Run(iterations int) {
> log.Debug("entering Run method")
> ...
> nID := registerObject(n)
> defer unregisterObject(nID)
> ...
> // this will call some go function
> n.optRes = C.nlopt_optimize(n.gopt, 
> (*C.double)(unsafe.Pointer(&x[0])), &maxf)
> 
> log.Debug("leaving Run method")
> }
>
>
> Here's what I see in my logs:
>
> entering Run method
> register: 1 (0xc82000a900)
> ... other messages, no "leaving Run method" ...
> unregister: 1 (0xc82000a900)
> panic: interface conversion: interface {} is nil, not *optimize.NLOPT
> (this panic happens because something was prematurely unregistered)
>
> So defer is executed before the method exits.
>
> I tried this in go v1.5 and v1.7, linux64. Sometimes it happens not 
> immediately, but after some time.
>
> Are there any special defer rules regarding cgo & callbacks which I do not 
> know?
>
> Thanks a lot for your suggestions,
> Iakov
>

-- 
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 parser

2016-11-10 Thread Sergio Hunter
I agree with you) But what do i do with this, It's exactly the same error.

четверг, 10 ноября 2016 г., 19:05:12 UTC+2 пользователь pierre...@gmail.com 
написал:
>
> We will get there but is is hard hitting your target when shooting in the 
> dark :).
>
> Remove white spaces:
> https://play.golang.org/p/_LktUPDhYW
>
> Le jeudi 10 novembre 2016 17:52:21 UTC+1, Sergio Hunter a écrit :
>>
>> Thanks for your help. 
>> Do you know what it means? 
>> 2016/11/10 18:46:21 invalid character '\u0085' looking for beginning of 
>> value
>> exit status 1
>>
>>
>> четверг, 10 ноября 2016 г., 18:32:40 UTC+2 пользователь 
>> pierre...@gmail.com написал:
>>>
>>> Sorry, I did not test it. This one passes the playground build (up to 
>>> the mysql driver not being found):
>>> https://play.golang.org/p/_WfTMOd-s6
>>>
>>> Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit :

 The compiler generates an error

 Test.go:71: undefined: o
 Test.go:85: cannot use nil as type Object in return argument





 четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь 
 pierre...@gmail.com написал:
>
> Ok, then something along those lines:
> https://play.golang.org/p/dMPQIrEdNN
>
> Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :
>>
>> Thanks so much for your answer. 
>> I'll try to explain what I need. I have a field "data",inside field 
>> has compress rows and text data(json), I need decompress data, but my 
>> code 
>> begins to unpack the file to text and compiler generates an error.
>> The logic is this: It reads "data" of the database, do 
>> "json.NewDecoder", if "json.NewDecoder" did not work - will "err", then 
>> if 
>> there are "err" is necessary to decompress and do again 
>> "json.NewDecoder". 
>> I hope you are understand me, thanks.
>>
>> четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon Ritchie 
>> написал:
>>>
>>> I'm also not sure what you are trying to do.  However, I think I can 
>>> see a bug in your code.
>>>
>>> First you run a database query to get a list of values from a field 
>>> called data.  This could produce up to 10 values.
>>>
>>> Next you have a loop which runs through the values and discards 
>>> them.  At the end of the loop, you have the data field from the last 
>>> record, and you have thrown away all the others.  Is this what you want?
>>>
>>> Finally, you unzip the last data field.
>>>
>>> So if your table contains 100 records, you will get 10 of them, 
>>> throw away the first 9 records and unzip the data from the last one.
>>>
>>> I hope this helps.
>>>
>>>

-- 
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 parser

2016-11-10 Thread pierre . curto
Then you need to provide sample data...

Le jeudi 10 novembre 2016 18:33:10 UTC+1, Sergio Hunter a écrit :
>
> I agree with you) But what do i do with this, It's exactly the same error.
>
> четверг, 10 ноября 2016 г., 19:05:12 UTC+2 пользователь 
> pierre...@gmail.com написал:
>>
>> We will get there but is is hard hitting your target when shooting in the 
>> dark :).
>>
>> Remove white spaces:
>> https://play.golang.org/p/_LktUPDhYW
>>
>> Le jeudi 10 novembre 2016 17:52:21 UTC+1, Sergio Hunter a écrit :
>>>
>>> Thanks for your help. 
>>> Do you know what it means? 
>>> 2016/11/10 18:46:21 invalid character '\u0085' looking for beginning of 
>>> value
>>> exit status 1
>>>
>>>
>>> четверг, 10 ноября 2016 г., 18:32:40 UTC+2 пользователь 
>>> pierre...@gmail.com написал:

 Sorry, I did not test it. This one passes the playground build (up to 
 the mysql driver not being found):
 https://play.golang.org/p/_WfTMOd-s6

 Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit :
>
> The compiler generates an error
>
> Test.go:71: undefined: o
> Test.go:85: cannot use nil as type Object in return argument
>
>
>
>
>
> четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь 
> pierre...@gmail.com написал:
>>
>> Ok, then something along those lines:
>> https://play.golang.org/p/dMPQIrEdNN
>>
>> Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :
>>>
>>> Thanks so much for your answer. 
>>> I'll try to explain what I need. I have a field "data",inside field 
>>> has compress rows and text data(json), I need decompress data, but my 
>>> code 
>>> begins to unpack the file to text and compiler generates an error.
>>> The logic is this: It reads "data" of the database, do 
>>> "json.NewDecoder", if "json.NewDecoder" did not work - will "err", then 
>>> if 
>>> there are "err" is necessary to decompress and do again 
>>> "json.NewDecoder". 
>>> I hope you are understand me, thanks.
>>>
>>> четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon 
>>> Ritchie написал:

 I'm also not sure what you are trying to do.  However, I think I 
 can see a bug in your code.

 First you run a database query to get a list of values from a field 
 called data.  This could produce up to 10 values.

 Next you have a loop which runs through the values and discards 
 them.  At the end of the loop, you have the data field from the last 
 record, and you have thrown away all the others.  Is this what you 
 want?

 Finally, you unzip the last data field.

 So if your table contains 100 records, you will get 10 of them, 
 throw away the first 9 records and unzip the data from the last one.

 I hope this helps.



-- 
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] Pure golang library to encode N-Quads

2016-11-10 Thread Johann Höchtl
Is there any?

I found https://github.com/Callidon/joseki which doesn't seem to support 
N-Quads and https://github.com/knakk/rdf seems to be incapable to serialize 
N-Quads.


-- 
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: postgres example using lib/pq

2016-11-10 Thread arbingersys
Here's a nice succinct 
example 
http://albertech.blogspot.com/2016/10/minimal-sql-select-example-for-go-and.html

On Wednesday, August 21, 2013 at 7:59:08 AM UTC-6, will wrote:
>
> Hi, 
> Can someone give me a basic example of pulling data from a postgres 
> database e.g. mydatabase for two parameters, firstname, lastname. Example 
> to use using lib/pq.
>
> Regards,
>
> Will
>

-- 
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 parser

2016-11-10 Thread Sergio Hunter
I can't because аccess to the database is only granted to me.
If leave my code and only add code which would be skip text rows and 
continues to unpack the archive?


четверг, 10 ноября 2016 г., 19:34:33 UTC+2 пользователь pierre...@gmail.com 
написал:
>
> Then you need to provide sample data...
>
> Le jeudi 10 novembre 2016 18:33:10 UTC+1, Sergio Hunter a écrit :
>>
>> I agree with you) But what do i do with this, It's exactly the same error.
>>
>> четверг, 10 ноября 2016 г., 19:05:12 UTC+2 пользователь 
>> pierre...@gmail.com написал:
>>>
>>> We will get there but is is hard hitting your target when shooting in 
>>> the dark :).
>>>
>>> Remove white spaces:
>>> https://play.golang.org/p/_LktUPDhYW
>>>
>>> Le jeudi 10 novembre 2016 17:52:21 UTC+1, Sergio Hunter a écrit :

 Thanks for your help. 
 Do you know what it means? 
 2016/11/10 18:46:21 invalid character '\u0085' looking for beginning of 
 value
 exit status 1


 четверг, 10 ноября 2016 г., 18:32:40 UTC+2 пользователь 
 pierre...@gmail.com написал:
>
> Sorry, I did not test it. This one passes the playground build (up to 
> the mysql driver not being found):
> https://play.golang.org/p/_WfTMOd-s6
>
> Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit :
>>
>> The compiler generates an error
>>
>> Test.go:71: undefined: o
>> Test.go:85: cannot use nil as type Object in return argument
>>
>>
>>
>>
>>
>> четверг, 10 ноября 2016 г., 17:56:58 UTC+2 пользователь 
>> pierre...@gmail.com написал:
>>>
>>> Ok, then something along those lines:
>>> https://play.golang.org/p/dMPQIrEdNN
>>>
>>> Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit :

 Thanks so much for your answer. 
 I'll try to explain what I need. I have a field "data",inside field 
 has compress rows and text data(json), I need decompress data, but my 
 code 
 begins to unpack the file to text and compiler generates an error.
 The logic is this: It reads "data" of the database, do 
 "json.NewDecoder", if "json.NewDecoder" did not work - will "err", 
 then if 
 there are "err" is necessary to decompress and do again 
 "json.NewDecoder". 
 I hope you are understand me, thanks.

 четверг, 10 ноября 2016 г., 13:03:28 UTC+2 пользователь Simon 
 Ritchie написал:
>
> I'm also not sure what you are trying to do.  However, I think I 
> can see a bug in your code.
>
> First you run a database query to get a list of values from a 
> field called data.  This could produce up to 10 values.
>
> Next you have a loop which runs through the values and discards 
> them.  At the end of the loop, you have the data field from the last 
> record, and you have thrown away all the others.  Is this what you 
> want?
>
> Finally, you unzip the last data field.
>
> So if your table contains 100 records, you will get 10 of them, 
> throw away the first 9 records and unzip the data from the last one.
>
> I hope this helps.
>
>

-- 
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] (GUI) Qt binding which supports Windows / macOS / Linux / Android / iOS / Sailfish OS / Raspberry Pi

2016-11-10 Thread the_recipe
Hey everyone,

I would like to officially announce the project I'm working on for a while 
now.
It's a binding for the Qt framework + some tools to help you with 
development and deployment of your Qt applications.

The most interesting feature of the Qt framework for the Go community is 
probably that it can be used to develop native looking GUI applications for 
various platforms without the need to make platform specific changes to 
your code.
Beside the GUI modules Qt also includes: a webengine (chromium), several 
multimedia functions, access to bluetooth + nfc, access to various hardware 
sensors, gamepad support, access to position informations and much more ...
The Qt article on wikipedia: https://en.wikipedia.org/wiki/Qt_(software)


There are two caveats for those who intent to use the binding:

1. You code won't be pure Go anymore, as this binding heavily relies on cgo.
2. The binding dynamically links to Qt's libraries, which results in 
25-50mb (depending on the platform) uncompressed libs that have to be 
deployed along with you binary.
(But it's also possible to link against the static Qt libs and remove this 
need. And there is also work being done to reduce the size of the dynamic 
libs in the upcoming versions of Qt.)


For the pro side, I should probably mention that:

1. The deployment to most platforms is pretty trivial (that includes cross 
compiling). (And there will be even more supported platforms in the future)
2. That the binding is almost complete and already supports most Qt modules 
(30+).
3. There are a lot of examples to get you started. (And porting over 
existing C++ examples should be super simple)


If someone is interested in testing it out, it can be found here:
https://github.com/therecipe/qt


Or if you just want to take a quick look and test the examples on Linux and 
you are familiar with Docker.
You could use one of the images as well: `docker pull therecipe/qt:base`
And simply run `qtdeploy build desktop` in one of the 
`$GOPATH/src/github.com/therecipe/qt/internal/examples/` sub-sub folders. 
(inside the container)
There will be a new folder created called `deploy`, which should contain 
everything that is needed to run the application on a regular 64-bit Linux 
system.


Please let me know what you think.
Any feedback is welcome :)

-- 
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] Why google cloud vision api cause memory issue when it is failed to detect

2016-11-10 Thread Dave Cheney
Thanks for your reply. I'm not sure we can help you, this is a mailing list 
about the Go programming language. 

-- 
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] question on profiling and instruction count display

2016-11-10 Thread Tieson Molly
Is there a way to use the native pprof tool to display the instruction 
count based on the sample instead of the duration for a cpu profile?

I saw this post on SO, but I was hoping to be able to use pprof and not a 
3rd party tool

http://stackoverflow.com/questions/28924550/golang-profile-with-pprof-how-to-get-hit-count-not-duration

I also saw a recent mention of the instruction cost here for the callgrind 
format

https://groups.google.com/forum/#!msg/golang-codereviews/CVOeJ4QF8C8/-Q9_B48dAwAJ


Best regards,

Ty

-- 
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] question on profiling and instruction count display

2016-11-10 Thread Dave Cheney
I'm afraid not, pprof does not record that information.

-- 
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: [ANN] (GUI) Qt binding which supports Windows / macOS / Linux / Android / iOS / Sailfish OS / Raspberry Pi

2016-11-10 Thread Rusco
Good to see some progress on the GUI front - I think you are up to 
something !
Rusco



On Thursday, 10 November 2016 20:34:36 UTC, therecipe wrote:
>
> Hey everyone,
>
> I would like to officially announce the project I'm working on for a while 
> now.
> It's a binding for the Qt framework + some tools to help you with 
> development and deployment of your Qt applications.
>
> The most interesting feature of the Qt framework for the Go community is 
> probably that it can be used to develop native looking GUI applications for 
> various platforms without the need to make platform specific changes to 
> your code.
> Beside the GUI modules Qt also includes: a webengine (chromium), several 
> multimedia functions, access to bluetooth + nfc, access to various hardware 
> sensors, gamepad support, access to position informations and much more ...
> The Qt article on wikipedia: https://en.wikipedia.org/wiki/Qt_(software)
>
>
> There are two caveats for those who intent to use the binding:
>
> 1. You code won't be pure Go anymore, as this binding heavily relies on 
> cgo.
> 2. The binding dynamically links to Qt's libraries, which results in 
> 25-50mb (depending on the platform) uncompressed libs that have to be 
> deployed along with you binary.
> (But it's also possible to link against the static Qt libs and remove this 
> need. And there is also work being done to reduce the size of the dynamic 
> libs in the upcoming versions of Qt.)
>
>
> For the pro side, I should probably mention that:
>
> 1. The deployment to most platforms is pretty trivial (that includes cross 
> compiling). (And there will be even more supported platforms in the future)
> 2. That the binding is almost complete and already supports most Qt 
> modules (30+).
> 3. There are a lot of examples to get you started. (And porting over 
> existing C++ examples should be super simple)
>
>
> If someone is interested in testing it out, it can be found here:
> https://github.com/therecipe/qt
>
>
> Or if you just want to take a quick look and test the examples on Linux 
> and you are familiar with Docker.
> You could use one of the images as well: `docker pull therecipe/qt:base`
> And simply run `qtdeploy build desktop` in one of the `$GOPATH/src/
> github.com/therecipe/qt/internal/examples/` 
>  sub-sub folders. 
> (inside the container)
> There will be a new folder created called `deploy`, which should contain 
> everything that is needed to run the application on a regular 64-bit Linux 
> system.
>
>
> Please let me know what you think.
> Any feedback is welcome :)
>

-- 
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: Tried to create a Varnish VMOD in go, but got "undefined reference" link errors

2016-11-10 Thread cristiantav
Did you find a way to get this to work?

On Saturday, October 24, 2015 at 9:09:51 PM UTC-4, Hiroaki Nakamura wrote:
>
> Hi.
>
> I tried to create an Varnish VMOD equivalent to 
> https://github.com/varnish/libvmod-example/tree/4.1 in go,
> but I got "undefined reference" link errors.
>
> ```
> gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -o 
> $WORK/command-line-arguments/_obj/_cgo_.o 
> $WORK/command-line-arguments/_obj/_cgo_main.o 
> $WORK/command-line-arguments/_obj/_cgo_export.o 
> $WORK/command-line-arguments/_obj/libvmod_example.cgo2.o 
> $WORK/command-line-arguments/_obj/vcc_if.cgo2.o -g -O2 -lvarnishapi
> # command-line-arguments
> /tmp/go-build219936183/command-line-arguments/_obj/libvmod_example.cgo2.o: 
> In function `_cgo_d098f44947dd_Cfunc_WS_Reserve':
> ./libvmod_example.go:64: undefined reference to `WS_Reserve'
> /tmp/go-build219936183/command-line-arguments/_obj/libvmod_example.cgo2.o: 
> In function `_cgo_d098f44947dd_Cfunc_WS_Release':
> ./libvmod_example.go:50: undefined reference to `WS_Release'
> /usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../lib64/libvarnishapi.so: 
> undefined reference to `pow'
> /usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../lib64/libvarnishapi.so: 
> undefined reference to `round'
> collect2: error: ld returned 1 exit status
> make: *** [libvmod_example.so] Error 2
> ```
>
> My Dockerfiles for building this VMOD are at
>
> https://github.com/hnakamur/docker-varnish-vmods-development/tree/try_to_create_vmod_in_go
>
> I confirmed two functions WS_Reserve and WS_Release are not linked in 
> libvarnishapi.so
> (which is specified with -lvarnishapi above).
> I confirmed it with the following command which printed one line but 
> cache_ws.c is just mentioned in a comment.
>
> ```
> $ docker exec -it dockervarnishvmodsdevelopment_varnish_1 bash -l -c "cd 
> /root/rpmbuild/SOURCES/Varnish-Cache-varnish-4.1.0/lib && grep -R cache_ws 
> ."
> ./libvmod_std/vmod_std_querysort.c: /* We trust cache_ws.c to align 
> sensibly */
> ```
>
> Actually they are linked in varnishd executable.
>
> https://github.com/varnish/Varnish-Cache/blob/varnish-4.1.0/bin/varnishd/Makefile.am#L52
>
> Is there a way to work around these undefined references and build a VMOD 
> shared library successfully?
>
> Thanks,
> Hiroaki
>

-- 
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] rewriting html/template files

2016-11-10 Thread 'Jeff Hodges' via golang-nuts
I originally wrote this up as a GitHub issue, but I want to make sure I'm
not missing anything by emailing this list first.

It would be nice if it was easier to rewrite `html/template` files but the
current tools (`html/template` and `x/net/html`) seem to have a gap between
them. Maybe there's a way to do this that I've missed, so let me explain
the problems I wanted to solve in detail.

I'm trying to make it easy to support CSP inline hashing in my templates
without nagging users and requiring them to remember to use some custom
funcs instead of the usual HTML. It'd also be nice to have form-based CSRF
protection which would be implemented in a similar way. I'm sure there are
other similar rewrites, but these security-focused ones were the first I've
run into.

Both CSP inline hashing and form-based CSRF protection involve a developer
adding additional attributes or elements to a template. In the CSP inline
hashing case, it's an attribute or nonce added `script` tags. In form-based
CSRF protection, it can be a hidden `input` that sends up a per-request
token inside a `form` tag.

It would be nice to be able to, at parse time, not execution time, pull
apart a `html/template` template, inspect it for the relevant tags, and
then change the template for the user instead of returning an error if they
forgot the important elements. At parse time, the code has all the data it
needs to adjust the template. Similar to why `gofmt` is capable of
rewriting a file, not just telling a developer how to adjust the file,
adjusting a template automatically instead of telling them they made an
error would a much nicer experience for the developer.

In the form-based CSRF case, the template rewrite would be adding a `input`
tag that calls a template func (or struct value) that has the token data.
In the CSP inline hashing case, the rewrite would be detecting if the
`script` tag contained only static information and adding the hash
automatically, or returning an error if the developer needs to get involved
(usually, to handle the case of requesting javascript files from elsewhere
on the web).

However, `html/template` only has `text/template/parse` as its AST which
doesn't suffice for working at the level of HTML semantics. Folks have
offered up `x/net/html`'s `ParseFragment` as a solution but that doesn't
work well.

One problem is that `x/net/html`'s `ParseFragment` makes it difficult to
render exactly back what was in a template. Without providing a context
`*html.Node`, you'll get back a tree with additional bogus nodes added
around the outside. This doesn't work well because rewriting code may need
to behave differently depending on what context `*html.Node` is in play
instead of guessing that all templates are in `body` or whatever. But
calculating that context `*html.Node` is difficult since a template can be
loaded from other templates. That would involve writing similar template
loading code to what is already inside `text/template`.

A second problem since some of those templates will be called in different
escaping contexts, folks using `ParseFragment` have to re-do the escape
context code in `html/template` within `x/net/html`'s AST.

I haven't found a way to make my templates better without requiring the
developer to handle more of what would otherwise be easily automated
problems. Is there an obvious solution I'm missing that doesn't involve
giving up context escaping and the other goodies by using an alternate
templating library?

-- 
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: [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Hirotaka Yamamoto (ymmt2005)
Hi,

I had implemented and blogged the technique to properly wrap 
http.ResponseWriter:
http://ymmt2005.hatenablog.com/entry/2016/09/01/How_to_hack_Go%27s_http_Server_correctly

type StdResponseWriter interface {
http.ResponseWriter
io.ReaderFrom
http.Flusher
http.CloseNotifier
http.Hijacker
WriteString(data string) (int, error)
}

I think an interface like this should be provided in net/http package to
make it easy to capture the response.

2016年11月10日木曜日 20時09分32秒 UTC+9 Felix Geisendoerfer:
>
> Hi all,
>
> while working on instrumenting my application, I ran into the fact that 
> capturing metrics such as status codes from my own http.Handlers is 
> surprisingly difficult to get right.
>
> Therefor I created a package that hopefully avoids most of the common 
> pitfalls. 
>
> https://github.com/felixge/httpsnoop
>
> I would love for net/http experts to take a look at the "Why this package 
> exists" section of the README, as well as the horrible hack required to 
> make things work:
>
> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163
>
> Please let me know if you have suggestions for simpler approaches and/or 
> spot any bugs in my implementation.
>
> Thanks a lot!
> Felix Geisendörfer
>

-- 
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] Sub-Benchmark strange results.

2016-11-10 Thread Evan Digby
Is it expected that if multiple sub-benchmarks are run in the same 
benchmark, the cost of the setup will impact the results from the first 
benchmark but not the second?

func BenchmarkIntersection(b *testing.B) {
// Long setup -- ~5.5 seconds

b.Run("basic 1", func(b *testing.B) {
for i := 0; i < b.N; i++ {
// Do benchmark stuff
}
})
b.Run("basic 2", func(b *testing.B) {
for i := 0; i < b.N; i++ {
// Do benchmark stuff (EXACTLY THE SAME AS TEST 1)
}
})
}

Results in:

BenchmarkIntersection/basic_1-4   1 5521938867 ns/op
BenchmarkIntersection/basic_2-4   2 8.89 ns/op

Am I doing this wrong?

I don't see an issue raised against this--should I be raising one?


-- 
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: Sub-Benchmark strange results.

2016-11-10 Thread Dave Cheney
Can you post a runable sample so that other can try to reproduce your issue?

On Friday, 11 November 2016 12:06:21 UTC+11, Evan Digby wrote:
>
> Is it expected that if multiple sub-benchmarks are run in the same 
> benchmark, the cost of the setup will impact the results from the first 
> benchmark but not the second?
>
> func BenchmarkIntersection(b *testing.B) {
> // Long setup -- ~5.5 seconds
>
> b.Run("basic 1", func(b *testing.B) {
> for i := 0; i < b.N; i++ {
> // Do benchmark stuff
> }
> })
> b.Run("basic 2", func(b *testing.B) {
> for i := 0; i < b.N; i++ {
> // Do benchmark stuff (EXACTLY THE SAME AS TEST 1)
> }
> })
> }
>
> Results in:
>
> BenchmarkIntersection/basic_1-4   1 5521938867 ns/op
> BenchmarkIntersection/basic_2-4   2 8.89 ns/op
>
> Am I doing this wrong?
>
> I don't see an issue raised against this--should I be raising one?
>
>
>

-- 
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: Sub-Benchmark strange results.

2016-11-10 Thread Evan Digby
I'm actually struggling to come up with a toy example that identically 
reproduces the results. I wonder if there are some compiler optimizations 
happening here.

The example isn't a lot of source, but has some IP and code that's not 
exactly in a state I wish to post publicly (rough draft). Is there 
somewhere I can post privately? If not, I can continue to try to reproduce 
with a non-IPish example. 

On Thursday, 10 November 2016 17:08:15 UTC-8, Dave Cheney wrote:
>
> Can you post a runable sample so that other can try to reproduce your 
> issue?
>
> On Friday, 11 November 2016 12:06:21 UTC+11, Evan Digby wrote:
>>
>> Is it expected that if multiple sub-benchmarks are run in the same 
>> benchmark, the cost of the setup will impact the results from the first 
>> benchmark but not the second?
>>
>> func BenchmarkIntersection(b *testing.B) {
>> // Long setup -- ~5.5 seconds
>>
>> b.Run("basic 1", func(b *testing.B) {
>> for i := 0; i < b.N; i++ {
>> // Do benchmark stuff
>> }
>> })
>> b.Run("basic 2", func(b *testing.B) {
>> for i := 0; i < b.N; i++ {
>> // Do benchmark stuff (EXACTLY THE SAME AS TEST 1)
>> }
>> })
>> }
>>
>> Results in:
>>
>> BenchmarkIntersection/basic_1-4   1 5521938867 ns/op
>> BenchmarkIntersection/basic_2-4   2 8.89 ns/op
>>
>> Am I doing this wrong?
>>
>> I don't see an issue raised against this--should I be raising one?
>>
>>
>>

-- 
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: Sub-Benchmark strange results.

2016-11-10 Thread Evan Digby
On a second glance, there's no real IP here. Let's not complicate things--I 
just ask that nobody judge the state of this code, unless that state is the 
reason for the strange benchmark results!

This won't run in playground since it's a benchmark, but provided as a 
nicer place to paste:

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

On Thursday, 10 November 2016 17:34:08 UTC-8, Evan Digby wrote:
>
> I'm actually struggling to come up with a toy example that identically 
> reproduces the results. I wonder if there are some compiler optimizations 
> happening here.
>
> The example isn't a lot of source, but has some IP and code that's not 
> exactly in a state I wish to post publicly (rough draft). Is there 
> somewhere I can post privately? If not, I can continue to try to reproduce 
> with a non-IPish example. 
>
> On Thursday, 10 November 2016 17:08:15 UTC-8, Dave Cheney wrote:
>>
>> Can you post a runable sample so that other can try to reproduce your 
>> issue?
>>
>> On Friday, 11 November 2016 12:06:21 UTC+11, Evan Digby wrote:
>>>
>>> Is it expected that if multiple sub-benchmarks are run in the same 
>>> benchmark, the cost of the setup will impact the results from the first 
>>> benchmark but not the second?
>>>
>>> func BenchmarkIntersection(b *testing.B) {
>>> // Long setup -- ~5.5 seconds
>>>
>>> b.Run("basic 1", func(b *testing.B) {
>>> for i := 0; i < b.N; i++ {
>>> // Do benchmark stuff
>>> }
>>> })
>>> b.Run("basic 2", func(b *testing.B) {
>>> for i := 0; i < b.N; i++ {
>>> // Do benchmark stuff (EXACTLY THE SAME AS TEST 1)
>>> }
>>> })
>>> }
>>>
>>> Results in:
>>>
>>> BenchmarkIntersection/basic_1-4   1 5521938867 ns/op
>>> BenchmarkIntersection/basic_2-4   2 8.89 ns/op
>>>
>>> Am I doing this wrong?
>>>
>>> I don't see an issue raised against this--should I be raising one?
>>>
>>>
>>>

-- 
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 conv [3]int to []int ?

2016-11-10 Thread Dan Kortschak
They have different layouts in memory. Do you just want to do this:

package main

import (
"fmt"
)

func main() {
a := [3]int{1, 2, 3}
b := a[:]
fmt.Println(b)
}

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

If so, there's no need for unsafe. If not, what are you trying to do?

On Thu, 2016-11-10 at 21:50 -0800, steve tang wrote:
> Hi theres,
> 
>     I used unsafe.Pointer to  conv Type [3]int to Type []int, But it
> throws 
> a runtime error,  Could anybody tell me why? many thanks.  The test
> code is 
> as follows:
> 
> package main
> 
> import (
> "fmt"
> "unsafe"
> )
> 
> func main() {
> a := [3]int{1, 2, 3}
> b := *(*[]int)(unsafe.Pointer(&a))
> fmt.Println(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] How to conv [3]int to []int ?

2016-11-10 Thread steve tang
Hi theres,

I used unsafe.Pointer to  conv Type [3]int to Type []int, But it throws 
a runtime error,  Could anybody tell me why? many thanks.  The test code is 
as follows:

package main

import (
"fmt"
"unsafe"
)

func main() {
a := [3]int{1, 2, 3}
b := *(*[]int)(unsafe.Pointer(&a))
fmt.Println(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: JSON parser

2016-11-10 Thread Tamás Gulácsi
2016. november 10., csütörtök 21:20:46 UTC+1 időpontban Sergio Hunter a 
következőt írta:
>
> I can't because аccess to the database is only granted to me.
> If leave my code and only add code which would be skip text rows and 
> continues to unpack the archive?
>
>
We haven't asked for access to the db, just some sample code!

If you want to distinguish between (probably) JSON and other text, that's 
easy: JSON starts with '{'.
If you want to distinguish between gzipped and non-gzipped text, that's 
easy: gzip starts with "\x1f\x8b": http://www.ietf.org/rfc/rfc1952.txt
T

-- 
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] Concurrency and order of execution

2016-11-10 Thread mspaulding06
Hello,

I've written a small program to demonstrate what I am seeing.  If I use a 
channel as a semaphore and set the size of the channel to 1, I would expect 
that the executions of my handle function below would all be executed in 
order, but it's not.  For some reason the last item in the list is always 
handled first, and then the remaining items are handled in order.  Does 
anyone know why I see this behavior?

Program:

package main

import (
 "fmt"
 "sync"
 "time"
)

var wg sync.WaitGroup
var sem chan int

func handle(i int) {
 defer wg.Done()
 fmt.Println("waiting: ", i)
 sem <- 1
 fmt.Println("processing: ", i)
 time.Sleep(1 * time.Second)
 <-sem
}

func main() {
 sem = make(chan int, 1)
 nums := []int{1, 2, 3, 4}

 for _, i := range nums {
   wg.Add(1)
   go handle(i)
 }
 wg.Wait()
}

Output:

waiting:  4
processing:  4
waiting:  1
waiting:  2
waiting:  3
processing:  1
processing:  2
processing:  3



-- 
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] Concurrency and order of execution

2016-11-10 Thread Henrik Johansson
I think there is a race on the WaitGroup. Add all of them before the loop.
It might not matter for what you are seeing but anyway.

What happens with an unbuffered channel?

On Fri, Nov 11, 2016, 07:08  wrote:

> Hello,
>
> I've written a small program to demonstrate what I am seeing.  If I use a
> channel as a semaphore and set the size of the channel to 1, I would expect
> that the executions of my handle function below would all be executed in
> order, but it's not.  For some reason the last item in the list is always
> handled first, and then the remaining items are handled in order.  Does
> anyone know why I see this behavior?
>
> Program:
>
> package main
>
> import (
>  "fmt"
>  "sync"
>  "time"
> )
>
> var wg sync.WaitGroup
> var sem chan int
>
> func handle(i int) {
>  defer wg.Done()
>  fmt.Println("waiting: ", i)
>  sem <- 1
>  fmt.Println("processing: ", i)
>  time.Sleep(1 * time.Second)
>  <-sem
> }
>
> func main() {
>  sem = make(chan int, 1)
>  nums := []int{1, 2, 3, 4}
>
>  for _, i := range nums {
>wg.Add(1)
>go handle(i)
>  }
>  wg.Wait()
> }
>
> Output:
>
> waiting:  4
> processing:  4
> waiting:  1
> waiting:  2
> waiting:  3
> processing:  1
> processing:  2
> processing:  3
>
>
>
> --
> 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] Concurrency and order of execution

2016-11-10 Thread Henrik Johansson
Also what makes you think that ordering is mandated? Any of the goroutines
can be scheduled to run. The odds of 1 running first seems intuitively
higher but the should be nothing stopping the last to run first.

On Fri, Nov 11, 2016, 07:11 Henrik Johansson  wrote:

> I think there is a race on the WaitGroup. Add all of them before the loop.
> It might not matter for what you are seeing but anyway.
>
> What happens with an unbuffered channel?
>
> On Fri, Nov 11, 2016, 07:08  wrote:
>
> Hello,
>
> I've written a small program to demonstrate what I am seeing.  If I use a
> channel as a semaphore and set the size of the channel to 1, I would expect
> that the executions of my handle function below would all be executed in
> order, but it's not.  For some reason the last item in the list is always
> handled first, and then the remaining items are handled in order.  Does
> anyone know why I see this behavior?
>
> Program:
>
> package main
>
> import (
>  "fmt"
>  "sync"
>  "time"
> )
>
> var wg sync.WaitGroup
> var sem chan int
>
> func handle(i int) {
>  defer wg.Done()
>  fmt.Println("waiting: ", i)
>  sem <- 1
>  fmt.Println("processing: ", i)
>  time.Sleep(1 * time.Second)
>  <-sem
> }
>
> func main() {
>  sem = make(chan int, 1)
>  nums := []int{1, 2, 3, 4}
>
>  for _, i := range nums {
>wg.Add(1)
>go handle(i)
>  }
>  wg.Wait()
> }
>
> Output:
>
> waiting:  4
> processing:  4
> waiting:  1
> waiting:  2
> waiting:  3
> processing:  1
> processing:  2
> processing:  3
>
>
>
> --
> 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] Concurrency and order of execution

2016-11-10 Thread Ian Lance Taylor
On Thu, Nov 10, 2016 at 10:03 PM,   wrote:
>
> I've written a small program to demonstrate what I am seeing.  If I use a
> channel as a semaphore and set the size of the channel to 1, I would expect
> that the executions of my handle function below would all be executed in
> order, but it's not.  For some reason the last item in the list is always
> handled first, and then the remaining items are handled in order.  Does
> anyone know why I see this behavior?

There is no relationship between the different goroutines started by
your program.  In effect they are all started simultaneously.  They
can start running in any order.  The specific order you happen to see
will depend on the number of CPUs on your system and how fast it is.

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] Re: Concurrency and order of execution

2016-11-10 Thread Dave Cheney
The runtime does not give any guarentee when you use a go statement if the 
goroutine being spawned will run immediately, or if control will remain 
with the original goroutine. 

This program, https://play.golang.org/p/-OcCzgt4Jy, which pauses all 
goroutines while they are being created exhibits the same behaviour as you 
see and may explain what you are seeing.

On Friday, 11 November 2016 17:08:39 UTC+11, mspaul...@gmail.com wrote:
>
> Hello,
>
> I've written a small program to demonstrate what I am seeing.  If I use a 
> channel as a semaphore and set the size of the channel to 1, I would expect 
> that the executions of my handle function below would all be executed in 
> order, but it's not.  For some reason the last item in the list is always 
> handled first, and then the remaining items are handled in order.  Does 
> anyone know why I see this behavior?
>
> Program:
>
> package main
>
> import (
>  "fmt"
>  "sync"
>  "time"
> )
>
> var wg sync.WaitGroup
> var sem chan int
>
> func handle(i int) {
>  defer wg.Done()
>  fmt.Println("waiting: ", i)
>  sem <- 1
>  fmt.Println("processing: ", i)
>  time.Sleep(1 * time.Second)
>  <-sem
> }
>
> func main() {
>  sem = make(chan int, 1)
>  nums := []int{1, 2, 3, 4}
>
>  for _, i := range nums {
>wg.Add(1)
>go handle(i)
>  }
>  wg.Wait()
> }
>
> Output:
>
> waiting:  4
> processing:  4
> waiting:  1
> waiting:  2
> waiting:  3
> processing:  1
> processing:  2
> processing:  3
>
>
>
>

-- 
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: [ANN] httpsnoop, an easy way to capture http related metrics (response time, bytes written, and http status code)

2016-11-10 Thread Felix Geisendörfer
> I think an interface like this should be provided in net/http package to
> make it easy to capture the response.

Yeah, I was hoping the new http tracing stuff would allow for this kind of 
instrumentation, but unfortunately it’s targeted at different aspects of the 
request/response cycle.

Cheers
Felix

> On 11 Nov 2016, at 00:55, Hirotaka Yamamoto (ymmt2005)  
> wrote:
> 
> Hi,
> 
> I had implemented and blogged the technique to properly wrap 
> http.ResponseWriter:
> http://ymmt2005.hatenablog.com/entry/2016/09/01/How_to_hack_Go%27s_http_Server_correctly
> 
> type StdResponseWriter interface {
>   http.ResponseWriter
>   io.ReaderFrom
>   http.Flusher
>   http.CloseNotifier
>   http.Hijacker
>   WriteString(data string) (int, error)
> }
> 
> I think an interface like this should be provided in net/http package to
> make it easy to capture the response.
> 
> 2016年11月10日木曜日 20時09分32秒 UTC+9 Felix Geisendoerfer:
> Hi all,
> 
> while working on instrumenting my application, I ran into the fact that 
> capturing metrics such as status codes from my own http.Handlers is 
> surprisingly difficult to get right.
> 
> Therefor I created a package that hopefully avoids most of the common 
> pitfalls. 
> 
> https://github.com/felixge/httpsnoop 
> 
> I would love for net/http experts to take a look at the "Why this package 
> exists" section of the README, as well as the horrible hack required to make 
> things work:
> 
> https://github.com/felixge/httpsnoop/blob/master/wrap.go#L44-L163 
> 
> 
> Please let me know if you have suggestions for simpler approaches and/or spot 
> any bugs in my implementation.
> 
> Thanks a lot!
> Felix Geisendörfer
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/-I5IZgJosYE/unsubscribe 
> .
> To unsubscribe from this group and all its topics, 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 conv [3]int to []int ?

2016-11-10 Thread steve tang
Thanks,  But I want them hold same data addrs.  So I just changed your code 
to follows:
a := [3]int{1, 2, 3}
b := (&a)[:]



On Friday, November 11, 2016 at 1:55:06 PM UTC+8, kortschak wrote:
>
> They have different layouts in memory. Do you just want to do this: 
>
> package main 
>
> import ( 
> "fmt" 
> ) 
>
> func main() { 
> a := [3]int{1, 2, 3} 
> b := a[:] 
> fmt.Println(b) 
> } 
>
> https://play.golang.org/p/OBY7g3azBE 
>
> If so, there's no need for unsafe. If not, what are you trying to do? 
>
> On Thu, 2016-11-10 at 21:50 -0800, steve tang wrote: 
> > Hi theres, 
> > 
> > I used unsafe.Pointer to  conv Type [3]int to Type []int, But it 
> > throws  
> > a runtime error,  Could anybody tell me why? many thanks.  The test 
> > code is  
> > as follows: 
> > 
> > package main 
> > 
> > import ( 
> > "fmt" 
> > "unsafe" 
> > ) 
> > 
> > func main() { 
> > a := [3]int{1, 2, 3} 
> > b := *(*[]int)(unsafe.Pointer(&a)) 
> > fmt.Println(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.