[go-nuts] Re: Ternary ... again

2018-08-14 Thread Agniva De Sarker
Your answer is here 
- https://tip.golang.org/doc/faq#Does_Go_have_a_ternary_form.


On Tuesday, 14 August 2018 22:13:37 UTC+5:30, Mark Volkmann wrote:
>
> I’m new to Go and I imagine the idea of adding a ternary operator to Go 
> has been discussed many times. Rather than repeat that, can someone point 
> me to a discussion about why Go doesn’t add this? I’m struggling to 
> understand why it is desirable to write code like this: 
>
> var color 
> if temperature > 100 { 
> color = “red” 
> } else { 
> color = “blue” 
> } 
>
> Instead of this: 
>
> var color = temperature > 100 ? “red” : “blue” 
>
> Is the ternary really so confusing that it justifies writing 6 lines of 
> code instead of 1? I realize I could eliminate two lines like the 
> following, but this isn’t a good idea if the values come from function 
> calls since there would sometimes be needless function calls. 
>
> var color = “blue” 
> if temperature > 100 { 
> color = “red” 
> } 
>
> --- 
> R. Mark Volkmann 
> Object Computing, Inc.

-- 
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: Does the ecosystem need a standard interface for vector graphic?

2018-08-14 Thread george . moschovitis

>
>  inspired from the canvas html5 API.
>

That's another option, but maybe it's optimized for raster-graphics rather 
than vector graphics?

-- 
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 "strings" package exists ?

2018-08-14 Thread Ian Lance Taylor
On Tue, Aug 14, 2018 at 7:37 PM,   wrote:
>
> Why not define the methods on type "string" ?
> I look up the document, strings package handles string with UTF-8 encoding.
> is it the reason ?
> if not, it's design decision or any other reasons ?

1. None of the types defined by the language have methods.

2. Some of the functions in the strings package, such as strings.Join,
don't make a lot of sense as methods.

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] unrecognized import paths error while using go get

2018-08-14 Thread Ian Lance Taylor
On Tue, Aug 14, 2018 at 5:52 PM, Amandeep Gautam
 wrote:
> Hi,
>I installed gccgo on Solaris 11.3 using: sudo /opt/csw/bin/pkgutil -y -i
> gcc5core
>
> Below is the output of go-5.5 env:
>
> amandeep@s113ldom1:~$ go-5.5 env
> GOARCH="sparc"
> GOBIN=""
> GOCHAR=""
> GOEXE=""
> GOHOSTARCH="sparc"
> GOHOSTOS="solaris"
> GOOS="solaris"
> GOPATH="/home/amandeep/"
> GORACE=""
> GOROOT="/opt/csw"
> GOTOOLDIR="/opt/csw/libexec/gcc/sparc-sun-solaris2.10/5.5.0"
> CC="/opt/csw/bin/gcc-5.5"
> GOGCCFLAGS="-fPIC -fmessage-length=0"
> CXX="/opt/csw/bin/g++-5.5"
> CGO_ENABLED="0"
>
> I get unrecognized path error while trying to get a package:
>
> amandeep@s113ldom1:~$ go-5.5 get github.com/dgrijalva/jwt-go
> package bytes: unrecognized import path "bytes"
> package crypto: unrecognized import path "crypto"
> package crypto/ecdsa: unrecognized import path "crypto/ecdsa"
> package crypto/hmac: unrecognized import path "crypto/hmac"
> package crypto/rand: unrecognized import path "crypto/rand"
> package crypto/rsa: unrecognized import path "crypto/rsa"
> package crypto/subtle: unrecognized import path "crypto/subtle"
> package crypto/x509: unrecognized import path "crypto/x509"
> package encoding/base64: unrecognized import path "encoding/base64"
> package encoding/json: unrecognized import path "encoding/json"
> package encoding/pem: unrecognized import path "encoding/pem"
> package errors: unrecognized import path "errors"
> package fmt: unrecognized import path "fmt"
> package math/big: unrecognized import path "math/big"
> package runtime: unrecognized import path "runtime"
> package strings: unrecognized import path "strings"
> package sync: unrecognized import path "sync"
> package time: unrecognized import path "time"
>
> Most of the other resources online suggest that it might be because of
> inappropriately set GOROOT, but I haven't modified it.
>
> After a little bit of digging I found that the .gox files are located in :
> /opt/csw/lib/go/5.5.0/sparc-sun-solaris2.10/
> For example, bytes.gox lives at
> /opt/csw/lib/go/5.5.0/sparc-sun-solaris2.10/bytes.gox
>
> Not sure what should be the correct settings here. Any suggestion
> appreciated.

Unfortunately I suspect that go get just doesn't work with that old
version.  The current version is GCC 8; go get should work with that
version.

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] Why "strings" package exists ?

2018-08-14 Thread isfrog
Why not define the methods on type "string" ? 
I look up the document, strings package handles string with UTF-8 encoding. 
is it the reason ? 
if not, it's design decision or any other reasons ?

-- 
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: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Dan Kortschak
Yes, that's understood. I'm just responding to the notion that it's a
bug for a package author to expect the compiler to do the right thing.

On Tue, 2018-08-14 at 15:56 -0700, Ian Lance Taylor wrote:
> On Tue, Aug 14, 2018 at 3:49 PM, Dan Kortschak
>  wrote:
> > 
> > 
> > This ignores the possibility that more than one alignment-sensitive
> > field might be needed. Requiring that they all be up front,
> > potentially
> > degrading readability flies in the face of the design principles of
> > the
> > language. This kind foot-gun in other languages is why many people
> > choose Go.
> Yes.  It's a bug.  It's listed as a bug at the bottom of
> https://golang.org/pkg/sync/atomic.  The problem is that we haven't
> figured out the right way to fix it.  It may require a language
> change.  Or see https://golang.org/issue/19057 .
> 
> Ian
> 
> 
> > 
> > On Tue, 2018-08-14 at 06:49 +, Jakob Borg wrote:
> > > 
> > > It’s a bug in the library if it uses 64 bit atomic operations
> > > without
> > > ensuring 64 bit alignment. Putting the alignment-required field
> > > at
> > > the top of the struct is the traditional method.
> > > 
> > > //jb
> > --
> > 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: AWS S3 Image Upload with Golang

2018-08-14 Thread maksach
Hi,

If I set Body to the out file itself, an item with the name of the outfile 
is uploaded to the S3 bucket, but that item is 0 bytes in size and when I 
click on it in S3 it doesn't appear, whereas with the buffer stuff, the 
image size in bytes is correct, but a black square shows up. This is how I 
get the out file in the first place:

file, header, err := r.FormFile("upload")

if err != nil {
fmt.Fprintln(w, err)
return
}

defer file.Close()

out, err := os.Create("/path/to/file/" + header.Filename)
if err != nil {
fmt.Fprintf(w, "Unable to create the file for writing. Check your write 
access privilege")
return
}

defer out.Close()

_, err = io.Copy(out, file)
if err != nil {
fmt.Fprintln(w, err)
}

I'm not sure why setting Body to the out file itself results in a 0 byte 
upload. Is there another way to upload the image to s3?

Thanks

On Tuesday, August 14, 2018 at 6:42:50 AM UTC-7, helloPiers wrote:
>
> It's not clear what the type of "out" is, other than it has Stat() and 
> Read([]byte) methods, but, assuming it's an io.Reader at least, if you 
> examine the return values from Read, like:
>   n, err := out.Read(buffer)
> you may get a clue to what's going wrong, for example n might not be the 
> full size of the file, there might be an error, etc. Likewise it's worth 
> checking the error returned from Stat. 
>
>
> It might be that "out" already is a ReadSeekCloser (if it's an *io.File 
> for example) in which case you can set Body in the UploadInput just to 
> "out":
>
>  ...
>  Body: out,
>  ...
>
> and dispense with all the stuff related to buffer.
>
>
> On Tuesday, August 14, 2018 at 6:18:43 AM UTC+1, Sachin Makaram wrote:
>>
>> Hi,
>>
>> I am trying to upload a local image file to an AWS S3 bucket and return 
>> the public URL in Golang. This is the core Golang code I have written to 
>> interact with my S3 bucket:
>>
>> creds := 
>> credentials.NewSharedCredentials("/Users/username/.aws/credentials", 
>> "default")
>>
>> config := {
>> Region:  aws.String("us-west-2"),
>> Credentials: creds,
>> }
>>
>> sess := session.New(config)
>>
>> uploader := s3manager.NewUploader(sess, func(u *s3manager.Uploader) {
>> u.PartSize = 64 * 1024 * 1024 
>> u.LeavePartsOnError = true
>> })
>>
>> fmt.Println(header.Filename)
>>
>> fileInfo, _ := out.Stat()
>> var size int64 =  fileInfo.Size()
>> fmt.Println("size", size)
>> buffer := make([]byte, size) 
>>
>> out.Read(buffer)
>> fileBytes := bytes.NewReader(buffer)
>>
>> result, err := uploader.Upload({
>> Bucket: aws.String("bucket-name"),
>> Key: aws.String(header.Filename),
>> Body: aws.ReadSeekCloser(fileBytes),
>> ContentType: aws.String("image/jpeg"),
>> ACL: aws.String("public-read"),
>> })
>> if err != nil || result == nil {
>> log.Fatalln("Failed to upload", err)
>> }
>>
>> log.Println("Successfully uploaded to", result.Location)
>>
>> With this code, the file is uploaded successfully to my s3 bucket with 
>> the correct size in bytes, but when I click on the URL, a black square is 
>> displayed instead of the actual image. If I change the ContentType field to 
>> allow file types dynamically, when I click on the URL, it downloads the 
>> image, but the image cannot be opened because "it may have been damaged." 
>> How can I fix this Golang code to just upload an image to an S3 bucket and 
>> get the public URL as a result of that upload?
>>
>> This may be more of a debugging question pertaining to AWS S3 than 
>> Golang, but any help would be appreciated. Thank you!
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] unrecognized import paths error while using go get

2018-08-14 Thread Amandeep Gautam
Hi,
   I installed gccgo on Solaris 11.3 using: sudo /opt/csw/bin/pkgutil -y -i 
gcc5core

Below is the output of go-5.5 env:

amandeep@s113ldom1:~$ go-5.5 env
GOARCH="sparc"
GOBIN=""
GOCHAR=""
GOEXE=""
GOHOSTARCH="sparc"
GOHOSTOS="solaris"
GOOS="solaris"
GOPATH="/home/amandeep/"
GORACE=""
GOROOT="/opt/csw"
GOTOOLDIR="/opt/csw/libexec/gcc/sparc-sun-solaris2.10/5.5.0"
CC="/opt/csw/bin/gcc-5.5"
GOGCCFLAGS="-fPIC -fmessage-length=0"
CXX="/opt/csw/bin/g++-5.5"
CGO_ENABLED="0"

I get unrecognized path error while trying to get a package:

amandeep@s113ldom1:~$ go-5.5 get github.com/dgrijalva/jwt-go
package bytes: unrecognized import path "bytes"
package crypto: unrecognized import path "crypto"
package crypto/ecdsa: unrecognized import path "crypto/ecdsa"
package crypto/hmac: unrecognized import path "crypto/hmac"
package crypto/rand: unrecognized import path "crypto/rand"
package crypto/rsa: unrecognized import path "crypto/rsa"
package crypto/subtle: unrecognized import path "crypto/subtle"
package crypto/x509: unrecognized import path "crypto/x509"
package encoding/base64: unrecognized import path "encoding/base64"
package encoding/json: unrecognized import path "encoding/json"
package encoding/pem: unrecognized import path "encoding/pem"
package errors: unrecognized import path "errors"
package fmt: unrecognized import path "fmt"
package math/big: unrecognized import path "math/big"
package runtime: unrecognized import path "runtime"
package strings: unrecognized import path "strings"
package sync: unrecognized import path "sync"
package time: unrecognized import path "time"

Most of the other resources online suggest that it might be because of 
inappropriately set GOROOT, but I haven't modified it.

After a little bit of digging I found that the .gox files are located in : 
/opt/csw/lib/go/5.5.0/sparc-sun-solaris2.10/
For example, bytes.gox lives at 
/opt/csw/lib/go/5.5.0/sparc-sun-solaris2.10/bytes.gox

Not sure what should be the correct settings here. Any suggestion 
appreciated.

-- 
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 test -c` skips init from main while `go test` doesn't

2018-08-14 Thread jake6502
I am unable to reproduce using a small test app on either Windows or 
Ubuntu, using go 1.10.3. In all cases the init() function in main is run 
when the test binary is run. Perhaps you could provide a minimal 
reproducible example?

On Monday, August 13, 2018 at 8:21:30 PM UTC-4, Gert wrote:
>
> Hi, `go test` runs the main init but the binary created by 
>
> go test -c -a -tags 'netgo noplugin' -gcflags "all=-N -l"
>
> doesn't. Is this a bug? Also it's seems you can't compile static test 
> binaries only non test binaries can be compiled static?
>

-- 
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: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Ian Lance Taylor
On Tue, Aug 14, 2018 at 3:49 PM, Dan Kortschak
 wrote:
>
> This ignores the possibility that more than one alignment-sensitive
> field might be needed. Requiring that they all be up front, potentially
> degrading readability flies in the face of the design principles of the
> language. This kind foot-gun in other languages is why many people
> choose Go.

Yes.  It's a bug.  It's listed as a bug at the bottom of
https://golang.org/pkg/sync/atomic.  The problem is that we haven't
figured out the right way to fix it.  It may require a language
change.  Or see https://golang.org/issue/19057 .

Ian


> On Tue, 2018-08-14 at 06:49 +, Jakob Borg wrote:
>> It’s a bug in the library if it uses 64 bit atomic operations without
>> ensuring 64 bit alignment. Putting the alignment-required field at
>> the top of the struct is the traditional method.
>>
>> //jb
>
> --
> 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] Re: Does the ecosystem need a standard interface for vector graphic?

2018-08-14 Thread Sebastien Binet
FYI (and IIRC), the vg package from (now) gonum/plot is actually inspired
from the canvas html5 API.

-s

sent from my droid

On Wed, Aug 15, 2018, 00:45  wrote:

> A general interface would be extremely useful (at least to me ;-).
> I am not sure about the postscript-based API (I am not against it though)
> and I find the the name `image/gc` a bit confusing (vector <-> image, gc ~
> garbage-collector).
>
> --
> 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] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Dan Kortschak
This ignores the possibility that more than one alignment-sensitive
field might be needed. Requiring that they all be up front, potentially
degrading readability flies in the face of the design principles of the
language. This kind foot-gun in other languages is why many people
choose Go.

On Tue, 2018-08-14 at 06:49 +, Jakob Borg wrote:
> It’s a bug in the library if it uses 64 bit atomic operations without
> ensuring 64 bit alignment. Putting the alignment-required field at
> the top of the struct is the traditional method.
> 
> //jb

-- 
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: Does the ecosystem need a standard interface for vector graphic?

2018-08-14 Thread george . moschovitis
A general interface would be extremely useful (at least to me ;-).
I am not sure about the postscript-based API (I am not against it though) 
and I find the the name `image/gc` a bit confusing (vector <-> image, gc ~ 
garbage-collector).

-- 
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] streadway/amqp (RabbitMQ) manual Ack does not work after first message

2018-08-14 Thread Sotirios Mantziaris
c'mon, this is so stupid...
thanks man very much, this was actually the problem!
Kudos for finding the culprit!

On Wednesday, August 15, 2018 at 12:44:20 AM UTC+3, Justin Israel wrote:
>
>
>
> On Wed, Aug 15, 2018 at 9:33 AM Sotirios Mantziaris  > wrote:
>
>> I can see over the wire that i get messages from the server with 
>> Basic.Delivery.
>> The messages do not pop up out of the channel that channel.Consume 
>> returns when creating the connection.
>> I might read some where that channels do not play well with threads. I 
>> wonder if it is the same with goroutines, because i get the messages one 
>> one goroutine, send it to another via a channel where the messages get Ack 
>> or Nack.
>>
>> You said that your application has a similar pattern. Is the channel and 
>> Ack, Nack on the same goroutine? do you have code that i can look into?
>>
>
> My application is internal at work, so I can't share it. But I took a look 
> at your code and I think this might be your problem:
>
> https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go#L119
>
> You are only selecting once on the delivery channel, without a for loop. 
> So you pull one message and your goroutine exits and never delivers another 
> message.
>
> You should be fine sharing the messages between goroutines. All that 
> matters is that the message acks itself back with the tag you set.
>  
>
>>
>> On Wednesday, August 15, 2018 at 12:24:18 AM UTC+3, Justin Israel wrote:
>>
>>>
>>>
>>> On Wed, Aug 15, 2018 at 8:05 AM Sotirios Mantziaris  
>>> wrote:
>>>
 I have actually opened a thread in the rabbitmq-users list where i 
 checked through wireshark what goes over the wire. It is actually pretty 
 nice to see the flow.
 I have cross posted since i did not know if it is rabbitmq or my go 
 code...
 it seems that i get the next message from the wire but the code does 
 not get it at all...

>>>
>>> If I am reading that properly, you are saying that your message handler 
>>> is not actually getting triggered at all for subsequent messages? That 
>>> would mean you have some kind of blocking problem in your goroutines and 
>>> channels. I thought initially you were saying that you verified the handler 
>>> was constantly receiving messages and calling ack() but the ack never makes 
>>> it back to Rabbitmq
>>>
>>>
 On Tuesday, August 14, 2018 at 10:59:15 PM UTC+3, Justin Israel wrote:
>
>
>
> On Wed, Aug 15, 2018, 2:14 AM Sotirios Mantziaris  
> wrote:
>
>> hi,
>>
>> i have setup a "consumer" for a rabbitmq queue. Every delivery is put 
>> in a channel which is picked up by a goroutine.
>> After processing the delivery is then Ack or Nack based on the 
>> success of the processing.
>> It seems that the first one is processed ok but the rest cannot be 
>> Ack/Nack.
>> The ui of rabbitmq shows every message in a unacked state, which 
>> probably means that the consumer gets the message from the queue but 
>> something prevents it for being put in the above mentioned channel.
>>
>> The consume part of the queue can be found here : 
>> https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go
>> The processing goroutine can be found here: 
>> https://github.com/mantzas/patron/blob/amqp-lock/async/component.go
>>
>> Does anybody have a idea?
>>
>
> I have an application with a similar pattern where is manually acks 
> each message after the processing succeeds. So I can check your logic 
> against mine. In the meantime, can you clarify if you confirmed that 
> processing always happens locally and the ack does get called every time, 
> but you are just not seeing it deliver the ack to Rabbitmq? 
>
 -- 
>> 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...@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...@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 

Re: [go-nuts] Re: [golang-dev] Go 1.11 Release Candidate 1 is released

2018-08-14 Thread Ulderico Cirello
I apologize. I didn't see in the BCC and assumed it wasn't sent. For some
reasons I lost the email from the announcement list.

Il giorno mar 14 ago 2018 alle ore 18:45 Ian Lance Taylor 
ha scritto:

> On Tue, Aug 14, 2018 at 4:41 AM, Ulderico Cirello
>  wrote:
> >
> > Don't we send these announcements to golang-announcements anymore?
>
> It was sent to golang-announce:
> https://groups.google.com/forum/#!topic/golang-announce/792GrzfZ1tw .
>
> 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] streadway/amqp (RabbitMQ) manual Ack does not work after first message

2018-08-14 Thread Justin Israel
On Wed, Aug 15, 2018 at 9:33 AM Sotirios Mantziaris 
wrote:

> I can see over the wire that i get messages from the server with
> Basic.Delivery.
> The messages do not pop up out of the channel that channel.Consume returns
> when creating the connection.
> I might read some where that channels do not play well with threads. I
> wonder if it is the same with goroutines, because i get the messages one
> one goroutine, send it to another via a channel where the messages get Ack
> or Nack.
>
> You said that your application has a similar pattern. Is the channel and
> Ack, Nack on the same goroutine? do you have code that i can look into?
>

My application is internal at work, so I can't share it. But I took a look
at your code and I think this might be your problem:

https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go#L119

You are only selecting once on the delivery channel, without a for loop. So
you pull one message and your goroutine exits and never delivers another
message.

You should be fine sharing the messages between goroutines. All that
matters is that the message acks itself back with the tag you set.


>
> On Wednesday, August 15, 2018 at 12:24:18 AM UTC+3, Justin Israel wrote:
>
>>
>>
>> On Wed, Aug 15, 2018 at 8:05 AM Sotirios Mantziaris 
>> wrote:
>>
>>> I have actually opened a thread in the rabbitmq-users list where i
>>> checked through wireshark what goes over the wire. It is actually pretty
>>> nice to see the flow.
>>> I have cross posted since i did not know if it is rabbitmq or my go
>>> code...
>>> it seems that i get the next message from the wire but the code does not
>>> get it at all...
>>>
>>
>> If I am reading that properly, you are saying that your message handler
>> is not actually getting triggered at all for subsequent messages? That
>> would mean you have some kind of blocking problem in your goroutines and
>> channels. I thought initially you were saying that you verified the handler
>> was constantly receiving messages and calling ack() but the ack never makes
>> it back to Rabbitmq
>>
>>
>>> On Tuesday, August 14, 2018 at 10:59:15 PM UTC+3, Justin Israel wrote:



 On Wed, Aug 15, 2018, 2:14 AM Sotirios Mantziaris 
 wrote:

> hi,
>
> i have setup a "consumer" for a rabbitmq queue. Every delivery is put
> in a channel which is picked up by a goroutine.
> After processing the delivery is then Ack or Nack based on the success
> of the processing.
> It seems that the first one is processed ok but the rest cannot be
> Ack/Nack.
> The ui of rabbitmq shows every message in a unacked state, which
> probably means that the consumer gets the message from the queue but
> something prevents it for being put in the above mentioned channel.
>
> The consume part of the queue can be found here :
> https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go
> The processing goroutine can be found here:
> https://github.com/mantzas/patron/blob/amqp-lock/async/component.go
>
> Does anybody have a idea?
>

 I have an application with a similar pattern where is manually acks
 each message after the processing succeeds. So I can check your logic
 against mine. In the meantime, can you clarify if you confirmed that
 processing always happens locally and the ack does get called every time,
 but you are just not seeing it deliver the ack to Rabbitmq?

>>> --
> 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...@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] streadway/amqp (RabbitMQ) manual Ack does not work after first message

2018-08-14 Thread Justin Israel
On Wed, Aug 15, 2018 at 8:05 AM Sotirios Mantziaris 
wrote:

> I have actually opened a thread in the rabbitmq-users list where i checked
> through wireshark what goes over the wire. It is actually pretty nice to
> see the flow.
> I have cross posted since i did not know if it is rabbitmq or my go code...
> it seems that i get the next message from the wire but the code does not
> get it at all...
>

If I am reading that properly, you are saying that your message handler is
not actually getting triggered at all for subsequent messages? That would
mean you have some kind of blocking problem in your goroutines and
channels. I thought initially you were saying that you verified the handler
was constantly receiving messages and calling ack() but the ack never makes
it back to Rabbitmq


> On Tuesday, August 14, 2018 at 10:59:15 PM UTC+3, Justin Israel wrote:
>>
>>
>>
>> On Wed, Aug 15, 2018, 2:14 AM Sotirios Mantziaris 
>> wrote:
>>
>>> hi,
>>>
>>> i have setup a "consumer" for a rabbitmq queue. Every delivery is put in
>>> a channel which is picked up by a goroutine.
>>> After processing the delivery is then Ack or Nack based on the success
>>> of the processing.
>>> It seems that the first one is processed ok but the rest cannot be
>>> Ack/Nack.
>>> The ui of rabbitmq shows every message in a unacked state, which
>>> probably means that the consumer gets the message from the queue but
>>> something prevents it for being put in the above mentioned channel.
>>>
>>> The consume part of the queue can be found here :
>>> https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go
>>> The processing goroutine can be found here:
>>> https://github.com/mantzas/patron/blob/amqp-lock/async/component.go
>>>
>>> Does anybody have a idea?
>>>
>>
>> I have an application with a similar pattern where is manually acks each
>> message after the processing succeeds. So I can check your logic against
>> mine. In the meantime, can you clarify if you confirmed that processing
>> always happens locally and the ack does get called every time, but you are
>> just not seeing it deliver the ack to Rabbitmq?
>>
> --
>>> 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.
>

-- 
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] Extending deadline for logging

2018-08-14 Thread rbz via golang-nuts
I'm working on a service that write some log info to spanner when it's done 
responding to a request. 
However, the service uses the context's deadline to write to spanner, so if 
the deadline expires due to some long running RPC, the write to spanner 
fails (because the deadline expired), and we don't get any log info.

What's the best practice for dealing with this situation?

-- 
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] streadway/amqp (RabbitMQ) manual Ack does not work after first message

2018-08-14 Thread Sotirios Mantziaris
I have actually opened a thread in the rabbitmq-users list where i checked 
through wireshark what goes over the wire. It is actually pretty nice to 
see the flow.
I have cross posted since i did not know if it is rabbitmq or my go code...
it seems that i get the next message from the wire but the code does not 
get it at all...

On Tuesday, August 14, 2018 at 10:59:15 PM UTC+3, Justin Israel wrote:
>
>
>
> On Wed, Aug 15, 2018, 2:14 AM Sotirios Mantziaris  > wrote:
>
>> hi,
>>
>> i have setup a "consumer" for a rabbitmq queue. Every delivery is put in 
>> a channel which is picked up by a goroutine.
>> After processing the delivery is then Ack or Nack based on the success of 
>> the processing.
>> It seems that the first one is processed ok but the rest cannot be 
>> Ack/Nack.
>> The ui of rabbitmq shows every message in a unacked state, which probably 
>> means that the consumer gets the message from the queue but something 
>> prevents it for being put in the above mentioned channel.
>>
>> The consume part of the queue can be found here : 
>> https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go
>> The processing goroutine can be found here: 
>> https://github.com/mantzas/patron/blob/amqp-lock/async/component.go
>>
>> Does anybody have a idea?
>>
>
> I have an application with a similar pattern where is manually acks each 
> message after the processing succeeds. So I can check your logic against 
> mine. In the meantime, can you clarify if you confirmed that processing 
> always happens locally and the ack does get called every time, but you are 
> just not seeing it deliver the ack to Rabbitmq? 
>
>> -- 
>> 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] streadway/amqp (RabbitMQ) manual Ack does not work after first message

2018-08-14 Thread Justin Israel
On Wed, Aug 15, 2018, 2:14 AM Sotirios Mantziaris 
wrote:

> hi,
>
> i have setup a "consumer" for a rabbitmq queue. Every delivery is put in a
> channel which is picked up by a goroutine.
> After processing the delivery is then Ack or Nack based on the success of
> the processing.
> It seems that the first one is processed ok but the rest cannot be
> Ack/Nack.
> The ui of rabbitmq shows every message in a unacked state, which probably
> means that the consumer gets the message from the queue but something
> prevents it for being put in the above mentioned channel.
>
> The consume part of the queue can be found here :
> https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go
> The processing goroutine can be found here:
> https://github.com/mantzas/patron/blob/amqp-lock/async/component.go
>
> Does anybody have a idea?
>

I have an application with a similar pattern where is manually acks each
message after the processing succeeds. So I can check your logic against
mine. In the meantime, can you clarify if you confirmed that processing
always happens locally and the ack does get called every time, but you are
just not seeing it deliver the ack to Rabbitmq?

> --
> 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: Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
i finaly have it :D in fact, the whole struct of httpbin returns have to be 
describe through different structures to works.

package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

func main() {
type User struct {
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}

type httpbin struct {
Origin string `json:"origin"`
Headers map[string]string `json:"headers"`
Myuser User `json:"json"`
}

u := User{Firstname: "doy", Lastname: "nic"}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(u)
res, _ := http.Post("https://httpbin.org/post;, "application/json; 
charset=utf-8", b)
newhttpbin := httpbin{}
json.NewDecoder(res.Body).Decode()
fmt.Println(newhttpbin.Myuser)
}



Le mardi 14 août 2018 20:15:21 UTC+2, nicolas...@yahoo.fr a écrit :
>
> when i try something like that:
>
> res, _ := http.Post("https://httpbin.org/post;, "application/json; 
> charset=utf-8", b)
> var newuser map[string]interface{}
> json.NewDecoder(res.Body).Decode()
> fmt.Println(newuser["json"])
>
> it prints me correctly the content a map containing the firstname & 
> lastname
>
> Le mardi 14 août 2018 12:19:20 UTC+2, nicolas...@yahoo.fr a écrit :
>>
>> Hello
>>
>> I need some assistance to decode a json content 
>>
>> I tried to use only usefull code to do it but don't success to retrieve 
>> the data part of the json result.
>>
>> var user struct {
>> Firstname string `json: "firstname"`
>> Lastname string `json: "lastname"`
>> Origin string `"origin"`
>> }
>>
>> jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"
>> }
>> jsonValue, _ := json.Marshal(jsonData)
>> response, err := http.Post("https://httpbin.org/post;, 
>> "application/json", bytes.NewBuffer(jsonValue))
>> defer response.Body.Close()
>> json.NewDecoder(response.Body).Decode()
>> fmt.Println(user)
>>
>> but this code only map the origin field not the firstname, and lastname 
>> part.
>>
>

-- 
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: go/format ouputs spurious newlines

2018-08-14 Thread naha
I've read rather a lot of formal documentation where the authors were not 
so careful with their language, particularly with distinctions between 
words like "undefined" and "invalid".

I think it a reasonable expectation that an object of type X returned by 
one function of a library be acceptable to other parts of that library that 
accept an object of type X.  Did I miss a section of the go/printer 
documentation that says that any Pos values in the input must be well 
defined?  I had no expectation that the printer would care about original 
source location.  I do expect that the expression of source locations in 
error messages would depend on well formed Pos information, but I wasn't 
complaining about being misdirected by error messages.

Anyway, I filed a ticket.  I looked at the source and believe it would not 
be easy to fix without making the entire parser be accepting of nil for 
File and FileSet values.  I have a workaround which is available to whoever 
else experiences this problem.  I hope no one else wastes a week trying to 
deal with the same problem.


On Tuesday, August 14, 2018 at 1:36:42 PM UTC-4, Marvin Renich wrote:
>
> * na...@mit.edu  > [180814 
> 11:43]: 
> > The documentation can be interpreted as you say. 
>
> I do not see how you can interpret it otherwise. 
>
> > If the resulting AST is subsequently inserted into a larger AST and then 
> > serialized, the source that is output can be syntactically invalid. 
> > 
> > It is unexpected (and I believe unreasonable) that serializing an AST 
> can 
> > produce code that can't be parsed. 
>
> If you insert an ast.Expr that was given to you with documented 
> deficiencies, I do not see why you would expect otherwise. 
>
> This sounds like a difference between what you want and what the package 
> is documented to do.  I.e. a feature request. 
>
> > There is no API for invalidating the Pos information of an AST.  In 
> order 
> > to make my application work, I needed to implement a function which 
> copied 
> > an entire AST except for its Pos information 
> > (
> https://raw.githubusercontent.com/MarkNahabedian/Goshua/master/rete/rule_compiler/nopos.go).
>  
>
> > 
> > 
> > Issue filed: 
> > https://github.com/golang/go/issues/26986 
>
> This seems like the correct approach to me, though I still think your 
> wording implies something wrong with the documentation and/or 
> implementation, as opposed to requesting an improvement to the design (I 
> do believe what you are asking for would be an improvement). 
>
> ...Marvin 
>
>

-- 
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: Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
and without the use of http.post, the encode / decode methods works :(

i also try this but it doesn't work too.

func main() {
type User struct {
Firstname string `json: "firstname"`
Lastname string `json: "lastname"`
}

type httpbin struct {
Origin string `json: "origin"`
Headers map[string]interface{} `json: "headers"`
Myuser User `json: "data"`
}

u := User{Firstname: "doy", Lastname: "nic"}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(u)
res, _ := http.Post("https://httpbin.org/post;, "application/json; 
charset=utf-8", b)
//var newuser map[string]interface{}
//newuser := User{}
newhttpbin := httpbin{}
json.NewDecoder(res.Body).Decode()
fmt.Println(newhttpbin.Myuser)
}Saisissez le code ici...



Le mardi 14 août 2018 20:15:21 UTC+2, nicolas...@yahoo.fr a écrit :
>
> when i try something like that:
>
> res, _ := http.Post("https://httpbin.org/post;, "application/json; 
> charset=utf-8", b)
> var newuser map[string]interface{}
> json.NewDecoder(res.Body).Decode()
> fmt.Println(newuser["json"])
>
> it prints me correctly the content a map containing the firstname & 
> lastname
>
> Le mardi 14 août 2018 12:19:20 UTC+2, nicolas...@yahoo.fr a écrit :
>>
>> Hello
>>
>> I need some assistance to decode a json content 
>>
>> I tried to use only usefull code to do it but don't success to retrieve 
>> the data part of the json result.
>>
>> var user struct {
>> Firstname string `json: "firstname"`
>> Lastname string `json: "lastname"`
>> Origin string `"origin"`
>> }
>>
>> jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"
>> }
>> jsonValue, _ := json.Marshal(jsonData)
>> response, err := http.Post("https://httpbin.org/post;, 
>> "application/json", bytes.NewBuffer(jsonValue))
>> defer response.Body.Close()
>> json.NewDecoder(response.Body).Decode()
>> fmt.Println(user)
>>
>> but this code only map the origin field not the firstname, and lastname 
>> part.
>>
>

-- 
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: Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
when i try something like that:

res, _ := http.Post("https://httpbin.org/post;, "application/json; 
charset=utf-8", b)
var newuser map[string]interface{}
json.NewDecoder(res.Body).Decode()
fmt.Println(newuser["json"])

it prints me correctly the content a map containing the ID & Balance

Le mardi 14 août 2018 18:43:30 UTC+2, alanw...@gmail.com a écrit :
>
> Have a try with jsonparser.Get()?
>
> 在 2018年8月14日星期二 UTC+8下午6:19:20,nicolas...@yahoo.fr写道:
>>
>> Hello
>>
>> I need some assistance to decode a json content 
>>
>> I tried to use only usefull code to do it but don't success to retrieve 
>> the data part of the json result.
>>
>> var user struct {
>> Firstname string `json: "firstname"`
>> Lastname string `json: "lastname"`
>> Origin string `"origin"`
>> }
>>
>> jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"
>> }
>> jsonValue, _ := json.Marshal(jsonData)
>> response, err := http.Post("https://httpbin.org/post;, 
>> "application/json", bytes.NewBuffer(jsonValue))
>> defer response.Body.Close()
>> json.NewDecoder(response.Body).Decode()
>> fmt.Println(user)
>>
>> but this code only map the origin field not the firstname, and lastname 
>> part.
>>
>

-- 
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: go/format ouputs spurious newlines

2018-08-14 Thread Marvin Renich
* n...@mit.edu  [180814 11:43]:
> The documentation can be interpreted as you say.

I do not see how you can interpret it otherwise.

> If the resulting AST is subsequently inserted into a larger AST and then 
> serialized, the source that is output can be syntactically invalid.
> 
> It is unexpected (and I believe unreasonable) that serializing an AST can 
> produce code that can't be parsed.

If you insert an ast.Expr that was given to you with documented
deficiencies, I do not see why you would expect otherwise.

This sounds like a difference between what you want and what the package
is documented to do.  I.e. a feature request.

> There is no API for invalidating the Pos information of an AST.  In order 
> to make my application work, I needed to implement a function which copied 
> an entire AST except for its Pos information 
> (https://raw.githubusercontent.com/MarkNahabedian/Goshua/master/rete/rule_compiler/nopos.go).
> 
> 
> Issue filed:
> https://github.com/golang/go/issues/26986

This seems like the correct approach to me, though I still think your
wording implies something wrong with the documentation and/or
implementation, as opposed to requesting an improvement to the design (I
do believe what you are asking for would be an improvement).

...Marvin

-- 
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] Ternary ... again

2018-08-14 Thread 'Axel Wagner' via golang-nuts
There is lots of discussion findable here:
https://groups.google.com/forum/#!searchin/golang-nuts/ternary%7Csort:date
There's a bit of discussion on the issue tracker:
https://github.com/golang/go/issues?utf8=%E2%9C%93=ternary+operator -- in
particular https://github.com/golang/go/issues/23248
There's more discussion on the reddit:
https://www.reddit.com/r/golang/comments/5dqpab/what_is_the_reasoning_behind_go_not_having_a/


On Tue, Aug 14, 2018 at 6:43 PM Mark Volkmann 
wrote:

> I’m new to Go and I imagine the idea of adding a ternary operator to Go
> has been discussed many times. Rather than repeat that, can someone point
> me to a discussion about why Go doesn’t add this? I’m struggling to
> understand why it is desirable to write code like this:
>
> var color
> if temperature > 100 {
> color = “red”
> } else {
> color = “blue”
> }
>
> Instead of this:
>
> var color = temperature > 100 ? “red” : “blue”
>
> Is the ternary really so confusing that it justifies writing 6 lines of
> code instead of 1? I realize I could eliminate two lines like the
> following, but this isn’t a good idea if the values come from function
> calls since there would sometimes be needless function calls.
>
> var color = “blue”
> if temperature > 100 {
> color = “red”
> }
>
> ---
> R. Mark Volkmann
> Object Computing, Inc.
>
> --
> 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 my program will panic?

2018-08-14 Thread Marvin Renich
* sheepbao  [180814 10:53]:
> Thank you for your detailed answer.
> I thought it would crash in this line (b.Z = "zz") of code. But it dose not 
> happen and the program print "zz".
> I don't understand why this program crash in return, not in b.Z = "zz". 
> Because I agree with your opinion,  The field Z of (*b) is beyond the 
> memory that was allocated 
> on the heap or reserved on the stack for a.

It does not crash when assigning to b.Z because b.Z references valid,
writable memory.  It overwrites what some other part of the code wrote
there for a different purpose.  It is not until the incorrect value is
read and used for the original intended purpose that incorrect behavior
can be noticed.  If nothing ever reads from that location afterwards,
than no incorrect behavior can be observed.

It might crash when assigning to b.Z if that memory location is not
writable or is not within the program's address space.  This could
happen, for instance, if the memory allocated for a were at the very end
of the program's address space.  This is extremely unlikely under most
circumstances.

Once you use unsafe to convert a pointer from one type to another, you
become responsible for ensuring that your use is appropriate; the
compiler no longer attempts to keep track of the memory to which the
unsafe pointer points.

...Marvin

-- 
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: [golang-dev] Go 1.11 Release Candidate 1 is released

2018-08-14 Thread Ian Lance Taylor
On Tue, Aug 14, 2018 at 4:41 AM, Ulderico Cirello
 wrote:
>
> Don't we send these announcements to golang-announcements anymore?

It was sent to golang-announce:
https://groups.google.com/forum/#!topic/golang-announce/792GrzfZ1tw .

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: Http/net - post and decode json data part

2018-08-14 Thread alanwang424
Have a try with jsonparser.Get()?

在 2018年8月14日星期二 UTC+8下午6:19:20,nicolas...@yahoo.fr写道:
>
> Hello
>
> I need some assistance to decode a json content 
>
> I tried to use only usefull code to do it but don't success to retrieve 
> the data part of the json result.
>
> var user struct {
> Firstname string `json: "firstname"`
> Lastname string `json: "lastname"`
> Origin string `"origin"`
> }
>
> jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"}
> jsonValue, _ := json.Marshal(jsonData)
> response, err := http.Post("https://httpbin.org/post;, 
> "application/json", bytes.NewBuffer(jsonValue))
> defer response.Body.Close()
> json.NewDecoder(response.Body).Decode()
> fmt.Println(user)
>
> but this code only map the origin field not the firstname, and lastname 
> part.
>

-- 
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] Ternary ... again

2018-08-14 Thread Mark Volkmann
I’m new to Go and I imagine the idea of adding a ternary operator to Go has 
been discussed many times. Rather than repeat that, can someone point me to a 
discussion about why Go doesn’t add this? I’m struggling to understand why it 
is desirable to write code like this:

var color
if temperature > 100 {
color = “red”
} else {
color = “blue”
}

Instead of this:

var color = temperature > 100 ? “red” : “blue”

Is the ternary really so confusing that it justifies writing 6 lines of code 
instead of 1? I realize I could eliminate two lines like the following, but 
this isn’t a good idea if the values come from function calls since there would 
sometimes be needless function calls.

var color = “blue”
if temperature > 100 {
color = “red”
}

---
R. Mark Volkmann
Object Computing, Inc.

-- 
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] Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
i try to parse the return of httpbin :)

Le mardi 14 août 2018 18:00:36 UTC+2, Ian Davis a écrit :
>
>
> On Tue, 14 Aug 2018, at 12:44 PM, nicolas_boiteux via golang-nuts wrote:
>
> the raw of response.body is this 
>
>
> {
>   "args": {}, 
>   "data": "{\"firstname\":\"Nic\",\"lastname\":\"Raboy\"}", 
>   "files": {}, 
>   "form": {}, 
>   "headers": {
> "Accept-Encoding": "gzip", 
> "Connection": "close", 
> "Content-Length": "38", 
> "Content-Type": "application/json", 
> "Host": "httpbin.org", 
> "User-Agent": "Go-http-client/1.1"
>   }, 
>   "json": {
>
> "firstname": "Nic", 
> "lastname": "Raboy"
>
>   }, 
>   "origin": "i remove my ip :)", 
>   "url": "https://httpbin.org/post;
> }
>
>
> for origin with or without the tag it works
>
>
> That looks like the output of httpbin.org which is a testing service. Is 
> that what you are trying to parse or do you have a real service that is 
> returning some JSON?
>
>
>
>
>

-- 
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] Http/net - post and decode json data part

2018-08-14 Thread Ian Davis

On Tue, 14 Aug 2018, at 12:44 PM, nicolas_boiteux via golang-nuts wrote:> the 
raw of response.body is this 
> 
> 
> {  "args": {},  "data":
> "{\"firstname\":\"Nic\",\"lastname\":\"Raboy\"}",  "files": {},
> "form": {},  "headers": {"Accept-Encoding": "gzip",
> "Connection": "close","Content-Length": "38","Content-Type":
> "application/json","Host": "httpbin.org","User-Agent": "Go-http-
> client/1.1"  },  "json": {> 
> "firstname": "Nic",
> "lastname": "Raboy"
>
>   }, "origin": "i remove my ip :)", "url": "
>   https://httpbin.org/post; }> 
> 
> for origin with or without the tag it works

That looks like the output of httpbin.org which is a testing service. Is
that what you are trying to parse or do you have a real service that is
returning some JSON?



-- 
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: go/format ouputs spurious newlines

2018-08-14 Thread naha
The documentation can be interpreted as you say.

If the resulting AST is subsequently inserted into a larger AST and then 
serialized, the source that is output can be syntactically invalid.

It is unexpected (and I believe unreasonable) that serializing an AST can 
produce code that can't be parsed.

There is no API for invalidating the Pos information of an AST.  In order 
to make my application work, I needed to implement a function which copied 
an entire AST except for its Pos information 
(https://raw.githubusercontent.com/MarkNahabedian/Goshua/master/rete/rule_compiler/nopos.go).


Issue filed:
https://github.com/golang/go/issues/26986


On Tuesday, August 14, 2018 at 10:12:10 AM UTC-4, Marvin Renich wrote:
>
> * na...@mit.edu  > [180814 
> 09:47]: 
> > The documentation for parser.ParseExpr says that the position 
> information 
> > in the AST it returns "is undefined".  I opserved the result as having 
> > position information.  This looks like a bug. 
> > 
> > https://play.golang.org/p/tpzqDF3EZ_S 
> > 
> > demonstrates this bug. 
>
> Why would you say this is a bug?  The documentation explicitly says the 
> position information is "undefined".  Undefined means that you might get 
> a value, but the value will be nonsense.  The value might coincidentally 
> be relevant, but you cannot rely on it because you will not be able to 
> determine whether it is nonsense, coincidentally relevant and correct, 
> or coincidentally relevant and incorrect. 
>
> Obtaining a coincidentally relevant and correct value for something that 
> is defined to be "undefined" is not a bug; it just happens sometimes. 
>
> "Undefined" may also be used when the current code returns something 
> correct, but the authors wish to reserve the right (i.e. not break Go 1 
> Compatibility) to change the implementation in a way that does not give 
> a meaningful value. 
>
> ...Marvin 
>
>

-- 
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] Does the ecosystem need a standard interface for vector graphic?

2018-08-14 Thread Robert Johnstone
In two recent projects, I have run up to the problem of creating vector 
graphics.  In one case, the project used gonum.org/v1/plot/vg to provide 
output, and in another github.com/llgcode/draw2d.  I've also 
found golang.org/x/image/vector.  In all of these cases, we have an 
interface that models fairly close the postscript model for drawing 2D 
graphics.  There is also duplication in the backends.  It would be nice if 
there was a standard ecosystem wide interface for painting 2D graphics.

I expect that providing implementations would be outside the scope of the 
language, but I see an approach similar to database/sql being useful here.  
There would be a package containing a standard interface to provide a 
graphics context (either image/gc or golang.org/x/image/gc).  

Has this been discussed elsewhere?  Would it be useful?

-- 
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: Compile to go languages?

2018-08-14 Thread 'David Chase' via golang-nuts
It's not a bad idea, except for the "idiomatic" part.  I guess it depends 
upon how idiomatic you want it to be.

Once upon a time, we compiled code to C (C++, Modula-3, and Cedar Mesa all 
had a compiler of that sort at one time or another).
Some people tried it for Java.

The advantage of targeting Go is that you get a low-latency GC and 
lightweight threads (Goroutines) "for free", as well as a decent bit of 
support for reflection, and the compiler will do a certain amount of escape 
analysis for you.
You might, for example, use goroutines to parallelize whole-array 
operations, if your source language had those (e.g.,m Fortran).

The disadvantage of targeting Go is that it's not that friendly to certain 
type systems, and you don't want to get into too much of a fight with the 
type system.
So Java would probably be a poor choice for a source language.  Smalltalk 
also might not work so well.


On Monday, August 13, 2018 at 6:48:59 PM UTC-4, Andrew Chambers wrote:
>
> Don't get me wrong, I love go, but also wonder if there are any languages 
> that compile to idiomatic go.
> I noticed reasonml compiles to javascript, and wondered to myself if there 
> is any value in such languages using go as a base for 
> interop to take advantage of the libraries and runtime.
>
> Any existing projects? Any thoughts about why its a good or bad idea, or 
> why it doesn't seem to exist already?
>

-- 
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 my program will panic?

2018-08-14 Thread sheepbao
Thank you for your detailed answer.
I thought it would crash in this line (b.Z = "zz") of code. But it dose not 
happen and the program print "zz".
I don't understand why this program crash in return, not in b.Z = "zz". 
Because I agree with your opinion,  The field Z of (*b) is beyond the 
memory that was allocated 
on the heap or reserved on the stack for a.

On Tuesday, August 14, 2018 at 9:57:05 PM UTC+8, Marvin Renich wrote:
>
> * sheepbao > [180813 23:45]: 
> > go version 
> > go version go1.10.2 darwin/amd64 
> > 
> > test code: 
> > 
> > func TestPoint(t *testing.T) { 
> > type A struct { 
> > X int 
> > Y string 
> > } 
> > type B struct { 
> > X int 
> > Y string 
> > Z string 
> > } 
> > 
> > a := A{X: 2, Y: "yy"} 
> > b := (*B)(unsafe.Pointer()) 
> > b.Z = "zz" 
> > 
> > fmt.Printf(" z: %v\n", b.Z) 
> > return 
> > } 
>
> Enough bytes are allocated for a (of type A).  It doesn't matter whether 
> they are on the stack or on the heap.  Now you use unsafe to make b a 
> pointer to type B that points to the same memory location where a was 
> allocated.  The field Z of (*b) is beyond the memory that was allocated 
> on the heap or reserved on the stack for a.  Neither the compiler (for 
> stack-reserved a) nor the runtime (for heap-allocated a) has made any 
> provision for ensuring that the memory immediately beyond a is not used 
> for anything else.  Writing to b.Z overwrites memory to which b has no 
> claim. 
>
> Both this code and the change in your subsequent message are simply 
> wrong.  Whether it crashes or not depends on the legitimate "owner" of 
> the memory at b.Z.  If it is a return address on the stack, a crash is 
> almost certain.  If it is memory on the heap that has not been allocated 
> yet, and will never be allocated in such a simple program, you might not 
> see any evidence that the code was written incorrectly. 
>
> ...Marvin 
>
>

-- 
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] streadway/amqp (RabbitMQ) manual Ack does not work after first message

2018-08-14 Thread Sotirios Mantziaris
hi,

i have setup a "consumer" for a rabbitmq queue. Every delivery is put in a 
channel which is picked up by a goroutine.
After processing the delivery is then Ack or Nack based on the success of 
the processing.
It seems that the first one is processed ok but the rest cannot be Ack/Nack.
The ui of rabbitmq shows every message in a unacked state, which probably 
means that the consumer gets the message from the queue but something 
prevents it for being put in the above mentioned channel.

The consume part of the queue can be found here 
: https://github.com/mantzas/patron/blob/amqp-lock/async/amqp/amqp.go
The processing goroutine can be found 
here: https://github.com/mantzas/patron/blob/amqp-lock/async/component.go

Does anybody have a idea?

-- 
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: go/format ouputs spurious newlines

2018-08-14 Thread Marvin Renich
* n...@mit.edu  [180814 09:47]:
> The documentation for parser.ParseExpr says that the position information 
> in the AST it returns "is undefined".  I opserved the result as having 
> position information.  This looks like a bug.
> 
> https://play.golang.org/p/tpzqDF3EZ_S
> 
> demonstrates this bug.

Why would you say this is a bug?  The documentation explicitly says the
position information is "undefined".  Undefined means that you might get
a value, but the value will be nonsense.  The value might coincidentally
be relevant, but you cannot rely on it because you will not be able to
determine whether it is nonsense, coincidentally relevant and correct,
or coincidentally relevant and incorrect.

Obtaining a coincidentally relevant and correct value for something that
is defined to be "undefined" is not a bug; it just happens sometimes.

"Undefined" may also be used when the current code returns something
correct, but the authors wish to reserve the right (i.e. not break Go 1
Compatibility) to change the implementation in a way that does not give
a meaningful value.

...Marvin

-- 
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 my program will panic?

2018-08-14 Thread Marvin Renich
* sheepbao  [180813 23:45]:
> go version
> go version go1.10.2 darwin/amd64
> 
> test code:
> 
> func TestPoint(t *testing.T) {
> type A struct {
> X int
> Y string
> }
> type B struct {
> X int
> Y string
> Z string
> }
> 
> a := A{X: 2, Y: "yy"}
> b := (*B)(unsafe.Pointer())
> b.Z = "zz"
> 
> fmt.Printf(" z: %v\n", b.Z)
> return
> }

Enough bytes are allocated for a (of type A).  It doesn't matter whether
they are on the stack or on the heap.  Now you use unsafe to make b a
pointer to type B that points to the same memory location where a was
allocated.  The field Z of (*b) is beyond the memory that was allocated
on the heap or reserved on the stack for a.  Neither the compiler (for
stack-reserved a) nor the runtime (for heap-allocated a) has made any
provision for ensuring that the memory immediately beyond a is not used
for anything else.  Writing to b.Z overwrites memory to which b has no
claim.

Both this code and the change in your subsequent message are simply
wrong.  Whether it crashes or not depends on the legitimate "owner" of
the memory at b.Z.  If it is a return address on the stack, a crash is
almost certain.  If it is memory on the heap that has not been allocated
yet, and will never be allocated in such a simple program, you might not
see any evidence that the code was written incorrectly.

...Marvin

-- 
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/format ouputs spurious newlines

2018-08-14 Thread naha
The documentation for parser.ParseExpr says that the position information 
in the AST it returns "is undefined".  I opserved the result as having 
position information.  This looks like a bug.

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

demonstrates this bug.


On Thursday, August 9, 2018 at 11:48:10 PM UTC-4, Mark Nahabedian wrote:
>
> I've done some further exploring.
>
> The expression computed by the line
>
> https://github.com/MarkNahabedian/Goshua/blob/ee72218487f39d2e97ade086df23dbcfcb4c2db3/rete/rule_compiler/rule_compiler.go#L214
> has both a valid Pos() and a valid End().  parseExpression is defined at
>
> https://github.com/MarkNahabedian/Goshua/blob/ee72218487f39d2e97ade086df23dbcfcb4c2db3/rete/rule_compiler/ast_helpers.go#L12
> It just panic-guards a call to parser.ParseExpr.  ParseExpr does
> not take a File or FileSet as argument, so how can the expression
> it returns have valid Pos values?
>
> I believe these Pos values are being misinterpreted by
> printer.indentList (defined at line 1085 of
> https://golang.org/src/go/printer/nodes.go) and causing it to
> iintroduce spurious newlines.
>
> After many hours of mindless coding I now have a function that
> will strip Pos information from an ast.  When parseExpression
> uses that function on its results the spuriouys newline probem
> goes away.
>
> I'm convinced that the ast returned by parser.ParseExpr should
> not contain any Pos values since they can't possibly be
> meaningful.
>
>
> On Wednesday, July 4, 2018 at 6:38:44 PM UTC-4, Mark Nahabedian wrote:
>>
>> I'm using go/ast and friends to generate go code.  I'm having trouble
>> with spurious newlines being added to the output.  These cause the
>> compiler to balk.
>>
>> For broader context, my code can be found at
>>
>> https://github.com/MarkNahabedian/Goshua/tree/master/rete/rule_compiler/rule_compiler.go
>> .
>>
>> The point of the code below is to build a map from strings that are
>> the names of go types to a function that returns true when invoked on
>> an object of that type.  This because I've not found a way to use
>> types as first class objects.
>>
>> // line 214
>> e := parseExpression(fmt.Sprintf(
>> `rete.EnsureTypeTestRegistered("%s", func(i interface{}) bool { _, ok := 
>> i.(%s); return ok })`,
>> pType, pType))
>> initFunc.Body.List = append(initFunc.Body.List,
>> { X: e})
>>
>> // line 221
>> newAstFile.Decls = append(newAstFile.Decls, initFunc)
>>
>> // line 224
>> writeFile(fset, newAstFile, outname)
>>
>>
>> parseExpression is defined in ast_helpers.go.  It calls
>> parser.ParseExpr and panics if there'sd an error.
>>
>> writeFile is defined in utils.go.  It calls format.Node to
>> serialize the generated source code.
>>
>>
>> Here is some sample output that illustrates the problem I'm observing.
>> Note that the spurious whitespace is not added consistently.  Two of
>> these three return statements get the error "not enough arguments to
>> return" which go away if the extra newlines are removed.
>>
>> rete.EnsureTypeTestRegistered("Couple", func(i interface{}) bool {
>> _, ok := i.(Couple)
>> return
>>
>> ok
>> })
>> rete.EnsureTypeTestRegistered("FaceToFace", func(i interface{}) bool {
>> _,
>> ok := i.(FaceToFace)
>> return ok
>> })
>> rete.EnsureTypeTestRegistered("Tandem", func(i interface{}) bool {
>> _, ok := i.(Tandem)
>> return
>>
>> ok
>> })
>>
>> Also observe that in the middle case spurious whitespace is added to
>> the assignment/declaration statement rather that the return statement.
>>
>> Why is this happening and how do I prevent it?
>>
>> Thanks.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: AWS S3 Image Upload with Golang

2018-08-14 Thread helloPiers
It's not clear what the type of "out" is, other than it has Stat() and 
Read([]byte) methods, but, assuming it's an io.Reader at least, if you 
examine the return values from Read, like:
  n, err := out.Read(buffer)
you may get a clue to what's going wrong, for example n might not be the 
full size of the file, there might be an error, etc. Likewise it's worth 
checking the error returned from Stat. 


It might be that "out" already is a ReadSeekCloser (if it's an *io.File for 
example) in which case you can set Body in the UploadInput just to "out":

 ...
 Body: out,
 ...

and dispense with all the stuff related to buffer.


On Tuesday, August 14, 2018 at 6:18:43 AM UTC+1, Sachin Makaram wrote:
>
> Hi,
>
> I am trying to upload a local image file to an AWS S3 bucket and return 
> the public URL in Golang. This is the core Golang code I have written to 
> interact with my S3 bucket:
>
> creds := 
> credentials.NewSharedCredentials("/Users/username/.aws/credentials", 
> "default")
>
> config := {
> Region:  aws.String("us-west-2"),
> Credentials: creds,
> }
>
> sess := session.New(config)
>
> uploader := s3manager.NewUploader(sess, func(u *s3manager.Uploader) {
> u.PartSize = 64 * 1024 * 1024 
> u.LeavePartsOnError = true
> })
>
> fmt.Println(header.Filename)
>
> fileInfo, _ := out.Stat()
> var size int64 =  fileInfo.Size()
> fmt.Println("size", size)
> buffer := make([]byte, size) 
>
> out.Read(buffer)
> fileBytes := bytes.NewReader(buffer)
>
> result, err := uploader.Upload({
> Bucket: aws.String("bucket-name"),
> Key: aws.String(header.Filename),
> Body: aws.ReadSeekCloser(fileBytes),
> ContentType: aws.String("image/jpeg"),
> ACL: aws.String("public-read"),
> })
> if err != nil || result == nil {
> log.Fatalln("Failed to upload", err)
> }
>
> log.Println("Successfully uploaded to", result.Location)
>
> With this code, the file is uploaded successfully to my s3 bucket with the 
> correct size in bytes, but when I click on the URL, a black square is 
> displayed instead of the actual image. If I change the ContentType field to 
> allow file types dynamically, when I click on the URL, it downloads the 
> image, but the image cannot be opened because "it may have been damaged." 
> How can I fix this Golang code to just upload an image to an S3 bucket and 
> get the public URL as a result of that upload?
>
> This may be more of a debugging question pertaining to AWS S3 than Golang, 
> but any help would be appreciated. Thank you!
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
the raw of response.body is this 

{
  "args": {}, 
  "data": "{\"firstname\":\"Nic\",\"lastname\":\"Raboy\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
"Accept-Encoding": "gzip", 
"Connection": "close", 
"Content-Length": "38", 
"Content-Type": "application/json", 
"Host": "httpbin.org", 
"User-Agent": "Go-http-client/1.1"
  }, 
  "json": {

"firstname": "Nic", 
"lastname": "Raboy"

  }, 
  "origin": "i remove my ip :)", 
  "url": "https://httpbin.org/post;
}

for origin with or without the tag it works

Le mardi 14 août 2018 13:14:40 UTC+2, Ian Davis a écrit :
>
>
> On Tue, 14 Aug 2018, at 11:19 AM, nicolas_boiteux via golang-nuts wrote:
>
> Hello
>
> I need some assistance to decode a json content 
>
> I tried to use only usefull code to do it but don't success to retrieve 
> the data part of the json result.
>
>
> var user struct {
> Firstname string `json: "firstname"`
> Lastname string `json: "lastname"`
> Origin string `"origin"`
> }
>
> jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"}
> jsonValue, _ := json.Marshal(jsonData)
> response, err := http.Post("https://httpbin.org/post;, 
> "application/json", bytes.NewBuffer(jsonValue))
> defer response.Body.Close()
> json.NewDecoder(response.Body).Decode()
> fmt.Println(user)
>
>
> but this code only map the origin field not the firstname, and lastname 
> part.
>
>
> Please show an example of the JSON you are receiving.
>
> You have some errors in your struct. Remove the spaces between json: and 
> the quote, like this: `json:"firstname"` 
>
> Also your origin tag is missing the json prefix.
>
>
> 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] Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
the raw of response.body is this 

{
  "args": {}, 
  "data": "{\"firstname\":\"Nic\",\"lastname\":\"Raboy\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
"Accept-Encoding": "gzip", 
"Connection": "close", 
"Content-Length": "38", 
"Content-Type": "application/json", 
"Host": "httpbin.org", 
"User-Agent": "Go-http-client/1.1"
  }, 
  "json": {
"firstname": "Nic", 
"lastname": "Raboy"
  }, 
  "origin": "212.194.99.97", 
  "url": "https://httpbin.org/post;
}

for origin with or without the tag it works

Le mardi 14 août 2018 13:14:40 UTC+2, Ian Davis a écrit :
>
>
> On Tue, 14 Aug 2018, at 11:19 AM, nicolas_boiteux via golang-nuts wrote:
>
> Hello
>
> I need some assistance to decode a json content 
>
> I tried to use only usefull code to do it but don't success to retrieve 
> the data part of the json result.
>
>
> var user struct {
> Firstname string `json: "firstname"`
> Lastname string `json: "lastname"`
> Origin string `"origin"`
> }
>
> jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"}
> jsonValue, _ := json.Marshal(jsonData)
> response, err := http.Post("https://httpbin.org/post;, 
> "application/json", bytes.NewBuffer(jsonValue))
> defer response.Body.Close()
> json.NewDecoder(response.Body).Decode()
> fmt.Println(user)
>
>
> but this code only map the origin field not the firstname, and lastname 
> part.
>
>
> Please show an example of the JSON you are receiving.
>
> You have some errors in your struct. Remove the spaces between json: and 
> the quote, like this: `json:"firstname"` 
>
> Also your origin tag is missing the json prefix.
>
>
> 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: [golang-dev] Go 1.11 Release Candidate 1 is released

2018-08-14 Thread Ulderico Cirello
Filippo,

Don't we send these announcements to golang-announcements anymore?

Ciao,
Ulderico

Il mar 14 ago 2018, 04:15 Filippo Valsorda  ha scritto:

> Hello gophers,
>
> We have just released go1.11rc1, a release candidate version of Go 1.11.
> It is cut from release-branch.go1.11 at the revision tagged go1.11rc1.
>
> Please try your production load tests and unit tests with the new version.
> Your help testing these pre-release versions is invaluable.
>
> Report any problems using the issue tracker:
> https://golang.org/issue/new
>
> If you have Go installed already, the easiest way to try go1.11rc1 is by
> using the go command:
> $ go get golang.org/dl/go1.11rc1
> $ go1.11rc1 download
>
> You can download binary and source distributions from the usual place:
> https://golang.org/dl/#go1.11rc1
>
> To find out what has changed in Go 1.11, read the draft release notes:
> https://tip.golang.org/doc/go1.11
>
> Alla prossima,
> Filippo for the Go Team
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-dev+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] Http/net - post and decode json data part

2018-08-14 Thread Ian Davis

On Tue, 14 Aug 2018, at 11:19 AM, nicolas_boiteux via golang-nuts wrote:> Hello
> 
> I need some assistance to decode a json content 
> 
> I tried to use only usefull code to do it but don't success to
> retrieve the data part of the json result.> 
> 
> var user struct {Firstname string `json: "firstname"`
> Lastname string `json: "lastname"`Origin string `"origin"` }
>
> jsonData := map[string]string{"firstname": "Nic", "lastname":
> "Raboy"} jsonValue, _ := json.Marshal(jsonData) response, err :=
> http.Post("https://httpbin.org/post;, "application/json",
> bytes.NewBuffer(jsonValue)) defer response.Body.Close()
> json.NewDecoder(response.Body).Decode() fmt.Println(user)> 
> 
> but this code only map the origin field not the firstname, and
> lastname part.
Please show an example of the JSON you are receiving.

You have some errors in your struct. Remove the spaces between json: and
the quote, like this: `json:"firstname"`
Also your origin tag is missing the json prefix.


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] Re: Examples testing with two newline, but only one newline

2018-08-14 Thread zpsyhapcst
Wow!!, Thank you

I think test files do not work in "Play golang" , but it seems work fine

I learn a new trick again.

messju mohr於 2018年8月13日星期一 UTC+8下午10時52分43秒寫道:
>
> Here is a running version that shows the original poster's problem: 
>  
>
> On Mon, Aug 13, 2018 at 07:16:08AM -0700, gary.wi...@victoriaplumb.com 
>  wrote: 
> >Your program doesn't work. 
> > 
> >On Saturday, 11 August 2018 09:10:04 UTC+1, 子風 wrote: 
> > 
> >  Hi 
> >  [1]https://play.golang.org/p/AIB-yJaExVu 
> >  When I want to use examples to test my code, I find something odd. 
> >  Example1 could pass, but Example2 failed 
> > 
> >--- FAIL: Example2 (0.00s) 
> >got: 
> >hello 
> >. 
> > 
> >123 
> >want: 
> >hello 
> >. 
> >123 
> >FAIL 
> >exit status 1 
> > 
> >  It seems Examples could only show one newline. 
> >  Is there a solution to solve it? Thanks 
> > 
> >-- 
> >You received this message because you are subscribed to the Google 
> Groups 
> >"golang-nuts" group. 
> >To unsubscribe from this group and stop receiving emails from it, 
> send an 
> >email to [2]golang-nuts...@googlegroups.com . 
> >For more options, visit [3]https://groups.google.com/d/optout. 
> > 
> > References 
> > 
> >Visible links 
> >1. https://play.golang.org/p/AIB-yJaExVu 
> >2. mailto:golang-nuts+unsubscr...@googlegroups.com  
> >3. 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: Examples testing with two newline, but only one newline

2018-08-14 Thread zpsyhapcst
Thank you

I have written a test, but when I saw the Examples, I thought it was better 
to test my function.

And I got the error. I am not sure whether it is a bug.

Jake Montgomery於 2018年8月14日星期二 UTC+8上午5時27分46秒寫道:
>
> Looks like a bug to me. I would suggest you open an issue.
>
> It is not clear to me what the intended behavior is. It is documented that 
> examples strip some white space when comparing output. So it may be 
> intentional that multiple white space lines are removed from the expected 
> output. In that case, IMO, the bug is that the same transformation is not 
> applied to the output before comparing. Conversely, it is possible that the 
> removal of the blank lines is the bug. 
>
> That said, since examples are documented to "strip white space", I would 
> remind you to also write actual tests, if the white space of the results 
> matters to you. 
>
>
> On Saturday, August 11, 2018 at 4:10:04 AM UTC-4, 子風 wrote:
>>
>> Hi
>>
>> https://play.golang.org/p/AIB-yJaExVu
>>
>> When I want to use examples to test my code, I find something odd.
>> Example1 could pass, but Example2 failed
>>
>> --- FAIL: Example2 (0.00s)
>>> got:
>>> hello
>>> .
>>>
>>> 123
>>> want:
>>> hello
>>> .
>>> 123
>>> FAIL
>>> exit status 1
>>
>>
>> It seems Examples could only show one newline.
>> Is there a solution to solve it? Thanks
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Http/net - post and decode json data part

2018-08-14 Thread nicolas_boiteux via golang-nuts
Hello

I need some assistance to decode a json content 

I tried to use only usefull code to do it but don't success to retrieve the 
data part of the json result.

var user struct {
Firstname string `json: "firstname"`
Lastname string `json: "lastname"`
Origin string `"origin"`
}

jsonData := map[string]string{"firstname": "Nic", "lastname": "Raboy"}
jsonValue, _ := json.Marshal(jsonData)
response, err := http.Post("https://httpbin.org/post;, 
"application/json", bytes.NewBuffer(jsonValue))
defer response.Body.Close()
json.NewDecoder(response.Body).Decode()
fmt.Println(user)

but this code only map the origin field not the firstname, and lastname 
part.

-- 
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: Can go-dockerclient be built with go modules?

2018-08-14 Thread Constantin Konstantinidis
An issue is already opened cf. https://github.com/golang/go/issues/22291

On Saturday, August 11, 2018 at 8:08:01 PM UTC+2, Joseph Lorenzini wrote:
>
>
> All:
>
> Using vgo, I haven't been able to build a go package with this library. 
> Using go 1.10, I can successfully build this library.
>
> https://github.com/fsouza/go-dockerclient
>
> When I attempt to vgo build, I get this error
>
> /Volumes/Repositories/go/pkg/mod/
> github.com/fsouza/go-dockerclient@v1.2.2/internal/archive/archive.go:21:2: 
> case-insensitive import collision: "github.com/sirupsen/logrus" and "
> github.com/Sirupsen/logrus"
>
>
> According to logrus project (github.com/sirupsen/logrus), the lowercase 
> variant should always be used. So I added, this replace to go.mod.
>
> vgo mod edit -replace=
> github.com/Sirupsen/logrus=github.com/sirupsen/logrus@v1.0.6
>
>
> But then vgo build fails, with this error:
>
> go: github.com/sirupsen/logrus@v1.0.6 used for two different module 
> paths (github.com/Sirupsen/logrus and github.com/sirupsen/logrus)
>
> Aside from opening an issue with the library author or forking the 
> library, Is there a standard way to handle this kind of problem so that a 
> program will build again?
>
> Thanks,
> Joe 
>

-- 
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: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Jakob Borg
It’s a bug in the library if it uses 64 bit atomic operations without ensuring 
64 bit alignment. Putting the alignment-required field at the top of the struct 
is the traditional method.

//jb

On 14 Aug 2018, at 08:45, Stephan Mühlstrasser 
mailto:stephan.muehlstras...@gmail.com>> wrote:

Am Montag, 13. August 2018 23:47:11 UTC+2 schrieb Dave Cheney:
I don’t think that will help. The problem is not cross compilation. The problem 
is when run in a 32bit environment the offset of that field is not guaranteed 
to be aligned to 8 bytes. You’ve got a 50/50 chance that each allocation will 
be properly aligned.

That sounds like a pretty severe compiler bug then. This makes it more or less 
impossible to use any third-party libraries with Go on ARM unless you check 
them and all their dependencies whether they use sync/atomic. Apparently the 
Google Cloud Go APIs fall into this category and should not be used on ARM 
32-bit.

--
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: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Stephan Mühlstrasser
Am Montag, 13. August 2018 23:47:11 UTC+2 schrieb Dave Cheney:
>
> I don’t think that will help. The problem is not cross compilation. The 
> problem is when run in a 32bit environment the offset of that field is not 
> guaranteed to be aligned to 8 bytes. You’ve got a 50/50 chance that each 
> allocation will be properly aligned.


That sounds like a pretty severe compiler bug then. This makes it more or 
less impossible to use any third-party libraries with Go on ARM unless you 
check them and all their dependencies whether they use sync/atomic. 
Apparently the Google Cloud Go APIs fall into this category and should not 
be used on ARM 32-bit.

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