Norbert Csibra | 25 Oct 11:33 2014
Picon

Communicating through net.Conn from multiple goroutines

Hi,

I'm trying to implement scgi protocol support to an existing xmlrpc library, using a custom rpc.ClientCodec.
My problem is, that the ClientCodec in the ReadResponseHeader expecting to set at least the "Seq" field of the Response struct.
As I understand from the source, it must match with the original "Seq" from the Request, otherwise may the wrong "Call" will return to the client.
The problem is, that the xmlrpc response does not provide the "Seq" number, neither the original "ServiceMethod" or arguments.
So if 2 rpc method invoked through the same Client from multiple goroutine, I can't identify in the response which one returned.
The obvious solution to do the calls sequentially, communicating between the "WriteRequest" and "ReadResponseHeader" calls with a channel for example, but it's ugly.

I thinking an other way, where creating a struct, saving the "Seq" and "ServiceMethod" and fire a separate goroutine, which do the call and read the response, save it to the same struct, then send it to the "ReadResponseHeader" method, through a channel.
This way I could be able to match the responses and the "Seq" id-s, I'm unsure only one thing.
The documentation of the net.Conn says, "Multiple goroutines may invoke methods on a Conn simultaneously", which is good, but what if:
Calling a long running rpc method from the A goroutine and a short running one from the B goroutine.
It means the "WriteRequest" will be invoked 2 times, so I creating 2 struct, e.g.: with "Seq" 0(A) and 1(B) and trying to read the responses from 2 separate goroutine.
I assume(depend from the server) it would be possible that the goroutine with "Seq" 0 read the response of the "Seq" 1 request, because the server finish earlier with the shorter rpc method.
In this case, 2 goroutine waits to read from the connection and when it's ready to receive, the go scheduler will pick one randomly, so may the responses will reverse.
Am I right?
If so, is there a way to make the rpc calls concurrent safely, without reversing the responses?

Thanks,
Norbert

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Oleku Konko | 25 Oct 10:00 2014
Picon

Write in Go (Fall 2014)

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Audrey Lim | 25 Oct 09:02 2014
Picon

Go: Write to header with TCP connection

I've implemented a TCP server with the following code structure from here:http://golang.org/pkg/net/#example_Listener

I'm trying to ping the TCP server from a browser. The TCP server is able to write to my browser. However, it is not able to write to the client header as it is not using the HTTP protocol. How do I keep the TCP protocol and connections but still be able to write to the browser's header?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Jeeyoung Kim | 25 Oct 08:12 2014
Picon

Are strings (and structs with strings) only dynamic-length key types in map?

I’ve been digging through the go reference doc, and I came to this conclusion. Mostly from the page:

https://golang.org/ref/spec#Comparison_operators

  • slices are not comparable.
  • there’s no way to allocate non-constant sized arrays in go - only slices.

This means that in order to store variable-length keys in golang, you need to encode it as string. You cannot (directly) use arbitrary-length array of integers, or array of structs as map keys.

Of course, strings in go is similar to strings in python2 - they’re “string of bytes”, so it’s not too hard to encode any kind of data to string.

I ran into this problem while trying to model a given problem. I wanted to have a map from a map of key-value pairs. map[map[KeyType]ValueType]T to use golang-type syntax to represent it. The inner map[KeyType]Value represents set of tag names and values associated with a given record of data.

In python, I would’ve modeled it as dict[sorted N-tuple of (KeyType,ValueType)] -> T. In Java, I would’ve have a composite object with single Map<KeyType, ValueType> as a member variable, with equals() to check map equality, hashCode() to return xor of all the hash values of the entries in the map. (I’m using xor because xor is commutative so we can calculate this by iterating through the map in arbitrary order).

In go, I would’ve wished to implement this as the python approach. If I can have the following code, it would be awesome.

type Pair struct { key KeyType val ValueType } m map[[]Pair]T;

Instead, I have to manually serialize to the map key, which can be error prone for various reasons.

  • Concatenating can be ambiguous. a + bc == ab + c. You can fix it by introducing a delimiter during concatenation, as long as the delimiter doesn’t appear in the input. If the delimiter appears in the input, you need to escape your input to avoid ambiguity.
  • Parsing back to the original, deserialized representation is also manual and error prone.

I’m currently wondering whether I am missing something very obvious, or this is the most idiomatic way to express this in go. I know struct as allowable key types in go is relatively recently introduced in go, so I’m wondering whether non-string dynamic length key type is being discussed in go.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
rneeraj.rai | 25 Oct 03:39 2014
Picon

incremental build

It seems that "go build -o foo foo.go" builds foo each time I issue the cmd
Is there to perform incremental build if my source or dependent packages have not changed ?

If this is a duplicate question, please point me to earlier posts.
I found some posts that were concerned with building packages, while I am concerned with building the final executable.

 thanks Neeraj

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
amirtaghavi2020 | 25 Oct 06:25 2014
Picon

What software can be written with golang?

hello
 What software can be written with golang? 
web?
mobile - android?
windows?
or all?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Nathaniel Nutter | 25 Oct 05:14 2014

Write in Go (Parody of Frozen's Let It Go)

I thought this was funny/cool.


Write in Go

https://www.youtube.com/watch?v=LJvEIjRBSDA

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Jean de Klerk | 25 Oct 04:19 2014
Picon

Is there a way to distinguish between binaries built with different GOOS / GOARCH?

I'm trying to write a test that go build works with flags, and all I can think of is to check if the GOOS/GOARCH has been set in binary_a differently than binary_b. Is this possible? Any other ideas?

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Audrey Lim | 25 Oct 03:28 2014
Picon

Go: accept different socket calls in one function

I'm trying to get my web server to accept different socket calls in one function. My code looks like this:

Go:

func handler(w io.Writer, r *io.ReadCloser) {

//do something

}

func main() {

http.HandleFunc("/", handler)

http.ListenAndServe(":3000", nil)

}

I get the error: cannot use handler (type func(io.Writer, *io.ReadCloser)) as type func(http.ResponseWriter, *http.Request) in argument to http.HandleFunc


Am I using interfaces wrongly? How do I implement this?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Alexandre Cesaro | 25 Oct 02:19 2014
Picon

Re: [ANN] gomail: a simple interface to send emails

If I add the "Unencoded" setting I want it to be respectful of MIME specifications. That's why I want to insert soft line breaks before 78 characters.
But I don't want to automatically modify the user's inputs (like adding a space before "From" or format=flowed in the header).

Anyway with theses changes you will be able to format your input to be f=f compliant.


On Sat, Oct 25, 2014 at 1:44 AM, Braden Pellett <braden <at> smashwords.com> wrote:
Oh, I don't think you need to concern yourself with the wrapping if it
doesn't seem generally applicable... I already am post-processing the
HTML part and have a wrapping method to generate the format=flowed plain
text, so I could just reuse that to prevent long lines in the HTML.

Alternatively, if you are going to do soft line breaks for long lines,
you could perhaps just go all in and provide a format=flowed formatting
option, :)

I just did it like this:

    https://github.com/daBrado/tplmail/blob/master/utils.go#L57-L77

...for a given line at a time, anyway.  Not that this is ideal... I'm
still new to Go..!

Thanks,
  Braden


On Sat, Oct 25, 2014 at 01:31:24AM +0200, Alexandre Cesaro wrote:
> Yes HTML would not be encoded.
>
> I can also add a soft line break after the last space before 78 characters.
>
> On Sat, Oct 25, 2014 at 1:16 AM, Braden Pellett <braden-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org>
> wrote:
>
> > Hi,
> >
> > Yeah, I think that could work.  Though, just to be clear, would that
> > mean that in a plain and html alternative message, the text/html part
> > would also not be encoded quoted-printable?  Which I think would mean I
> > need to be sure to not pass HTML with very long lines (i.e. more than
> > 998 characters before the newline)?
> >
> > Thanks,
> >   Braden
> >
> >
> > On Sat, Oct 25, 2014 at 12:58:28AM +0200, Alexandre Cesaro wrote:
> > > I can create a new Encoding
> > > <https://godoc.org/gopkg.in/gomail.v1#Encoding> named
> > > "Unencoded", so you can create your messages like that:
> > > msg := gomail.NewMessage(SetEncoding(gomail.Unencoded))
> > >
> > > It would set the Content-transfer-encoding header of the body to 8bit
> > > <https://tools.ietf.org/html/rfc2045#section-6.1> (but still encode
> > special
> > > characters in headers using quoted-printable).
> > >
> > > Is that fine with you?
> > >
> > > On Sat, Oct 25, 2014 at 12:18 AM, Braden Pellett <braden-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > Actually, since I end up formatting the plain text version myself, I
> > can
> > > > get pretty close to what I need simply by appending "; format=flowed"
> > to
> > > > the contentType string of the Message receiver's SetBody function.
> > > > (Though I don't know if that is an ideal way of going about it.)
> > > >
> > > > However, as per RFC3637, I'd like to be able to have the plain/text
> > body
> > > > (and only it) not be encoded as quoted printable.  Is there a way to
> > > > turn off quoted printable encoding for a given part of the mail
> > message?
> > > >
> > > > Thanks,
> > > >   Braden
> > > >
> > > >
> > > > On Thu, Oct 23, 2014 at 08:58:35AM -0700, braden-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org wrote:
> > > > > I just know I often see emails in my inbox with it, and those emails
> > end
> > > > up
> > > > > formated well in Mutt. :)
> > > > >
> > > > > Why do you say it works only for ASCII-only text?  I didn't see that
> > > > > mentioned in the RFC, and many of the format=flowed emails I receive
> > are
> > > > > UTF-8 (charset=UTF-8).
> > > > >
> > > > > Anyway, sure, I'll open an issue.
> > > > >
> > > > > Thanks,
> > > > >   Braden
> > > > >
> > > > > On Wednesday, October 22, 2014 11:55:19 PM UTC-7, Alexandre Cesaro
> > wrote:
> > > > > >
> > > > > > I'm not sure: it does not seem to be a very widespread standard
> > and it
> > > > > > only works with ASCII-only texts.
> > > > > >
> > > > > > However you can open an issue on Github if you want and we will
> > > > discuss it
> > > > > > there.
> > > > > >
> > > > > > On Wed, Oct 22, 2014 at 11:39 PM, <bra...-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org
> > > > <javascript:>>
> > > > > > wrote:
> > > > > >
> > > > > >> Hello,
> > > > > >>
> > > > > >> Thank you for the very useful package!
> > > > > >>
> > > > > >> I'm curious, do you have any plans to support the format=flowed
> > > > parameter
> > > > > >> for text/plain content types?  It seems like a nice way to send
> > plain
> > > > text.
> > > > > >>
> > > > > >> For reference:
> > > > > >>
> > > > > >>     http://www.ietf.org/rfc/rfc3676.txt
> > > > > >>     http://joeclark.org/ffaq.html
> > > > > >>
> > > > > >> I can look into implementing it, if you like.
> > > > > >>
> > > > > >> Thanks,
> > > > > >>   Braden
> > > > > >>
> > > > > >
> > > > > >
> > > >
> > > >
> >

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Alexandre Cesaro | 25 Oct 01:31 2014
Picon

Re: [ANN] gomail: a simple interface to send emails

Yes HTML would not be encoded.

I can also add a soft line break after the last space before 78 characters.

On Sat, Oct 25, 2014 at 1:16 AM, Braden Pellett <braden-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org> wrote:
Hi,

Yeah, I think that could work.  Though, just to be clear, would that
mean that in a plain and html alternative message, the text/html part
would also not be encoded quoted-printable?  Which I think would mean I
need to be sure to not pass HTML with very long lines (i.e. more than
998 characters before the newline)?

Thanks,
  Braden


On Sat, Oct 25, 2014 at 12:58:28AM +0200, Alexandre Cesaro wrote:
> I can create a new Encoding
> <https://godoc.org/gopkg.in/gomail.v1#Encoding> named
> "Unencoded", so you can create your messages like that:
> msg := gomail.NewMessage(SetEncoding(gomail.Unencoded))
>
> It would set the Content-transfer-encoding header of the body to 8bit
> <https://tools.ietf.org/html/rfc2045#section-6.1> (but still encode special
> characters in headers using quoted-printable).
>
> Is that fine with you?
>
> On Sat, Oct 25, 2014 at 12:18 AM, Braden Pellett <braden-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org>
> wrote:
>
> > Hi,
> >
> > Actually, since I end up formatting the plain text version myself, I can
> > get pretty close to what I need simply by appending "; format=flowed" to
> > the contentType string of the Message receiver's SetBody function.
> > (Though I don't know if that is an ideal way of going about it.)
> >
> > However, as per RFC3637, I'd like to be able to have the plain/text body
> > (and only it) not be encoded as quoted printable.  Is there a way to
> > turn off quoted printable encoding for a given part of the mail message?
> >
> > Thanks,
> >   Braden
> >
> >
> > On Thu, Oct 23, 2014 at 08:58:35AM -0700, braden-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org wrote:
> > > I just know I often see emails in my inbox with it, and those emails end
> > up
> > > formated well in Mutt. :)
> > >
> > > Why do you say it works only for ASCII-only text?  I didn't see that
> > > mentioned in the RFC, and many of the format=flowed emails I receive are
> > > UTF-8 (charset=UTF-8).
> > >
> > > Anyway, sure, I'll open an issue.
> > >
> > > Thanks,
> > >   Braden
> > >
> > > On Wednesday, October 22, 2014 11:55:19 PM UTC-7, Alexandre Cesaro wrote:
> > > >
> > > > I'm not sure: it does not seem to be a very widespread standard and it
> > > > only works with ASCII-only texts.
> > > >
> > > > However you can open an issue on Github if you want and we will
> > discuss it
> > > > there.
> > > >
> > > > On Wed, Oct 22, 2014 at 11:39 PM, <bra...-oWJPb6nRw2IoM3ANB2zruQ@public.gmane.org
> > <javascript:>>
> > > > wrote:
> > > >
> > > >> Hello,
> > > >>
> > > >> Thank you for the very useful package!
> > > >>
> > > >> I'm curious, do you have any plans to support the format=flowed
> > parameter
> > > >> for text/plain content types?  It seems like a nice way to send plain
> > text.
> > > >>
> > > >> For reference:
> > > >>
> > > >>     http://www.ietf.org/rfc/rfc3676.txt
> > > >>     http://joeclark.org/ffaq.html
> > > >>
> > > >> I can look into implementing it, if you like.
> > > >>
> > > >> Thanks,
> > > >>   Braden
> > > >>
> > > >
> > > >
> >
> >

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane