FAQ
https://gist.github.com/bradysullivan/6612701

I know there is a simple, more concise way to go about what I am doing.
Specifically posting the parameters in json, with the appropriate header.

Anyone have thoughts as to how to I can do this more idiomatically?

--
The information contained in this transmission contains potentially
privileged, export controlled and/or confidential information of Imageware
Systems, Inc. or its customers or partners. It is intended only to be read
by the person(s) named above and for no other purpose. You are hereby
notified that any dissemination, distribution, duplication of this communication
or use of its contents for any purpose not authorized expressly by
Imageware Systems, Inc. is strictly prohibited and could lead to both civil
and/or criminal penalties. If you are not the intended recipient, you are prohibited
to review the contents herein and please contact the sender by reply e-mail
and destroy all copies of the original message. To reply to our e-mail
administrator directly, please send an e-mail to emailadmin@iwsinc.com

--
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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rémy Oudompheng at Sep 18, 2013 at 6:44 pm

    On 2013/9/18 wrote:
    https://gist.github.com/bradysullivan/6612701

    I know there is a simple, more concise way to go about what I am doing.
    Specifically posting the parameters in json, with the appropriate header.

    Anyone have thoughts as to how to I can do this more idiomatically?
    This looks quite idiomatic to me. If you need a function to "post JSON
    to an URL and read result" you can write one and the code will become
    quite short.

    e.g.:

    func postJSON(url string, data interface{}) (result interface{}, err error)

    Rémy.

    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Carlos Castillo at Sep 20, 2013 at 9:55 pm
    On line 6, you can use bytes.NewReader instead of converting the data to a
    string and using strings.NewReader. This is clearer, shorter, and prevents
    making an extra copy of the data (ie: faster & less mem).

    Unless you are doing more with the header, client.Post (or the package wide
    http.Post), does all you need: resp, err := http.Post(posturl,
    "application/json", bytes.NewReader(data))

    I'm not saying it's more idiomatic, but since there are functions/methods
    that more precisely do what you want, you should probably use them. For me,
    saving lines of code and being more readable *is* more idiomatic for go,
    but I consider the later (readability) more important than the former.

    On Wednesday, September 18, 2013 10:41:58 AM UTC-7, Brady.S...@iwsinc.com
    wrote:
    https://gist.github.com/bradysullivan/6612701

    I know there is a simple, more concise way to go about what I am doing.
    Specifically posting the parameters in json, with the appropriate header.

    Anyone have thoughts as to how to I can do this more idiomatically?

    The information contained in this transmission contains potentially
    privileged, export controlled and/or confidential information of
    Imageware Systems, Inc. or its customers or partners. It is intended only
    to be read by the person(s) named above and for no other purpose. You
    are hereby notified that any dissemination, distribution, duplication of
    this communication or use of its contents for any purpose not authorized
    expressly by Imageware Systems, Inc. is strictly prohibited and could
    lead to both civil and/or criminal penalties. If you are not the intended
    recipient, you are prohibited to review the contents herein and please
    contact the sender by reply e-mail and destroy all copies of the original
    message. To reply to our e-mail administrator directly, please send an
    e-mail to email...@iwsinc.com <javascript:>
    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brady Sullivan at Sep 21, 2013 at 10:46 pm
    Thanks Carlos, those are exactly the comments I was looking for. The only
    problem with combining it into http.Post is I need to use SSL. So right now
    I am creating a transport, a client, and calling the request with client.Do
    in order to use SSL. Is there another way that you know of?
    On Friday, September 20, 2013 2:55:40 PM UTC-7, Carlos Castillo wrote:

    On line 6, you can use bytes.NewReader instead of converting the data to a
    string and using strings.NewReader. This is clearer, shorter, and prevents
    making an extra copy of the data (ie: faster & less mem).

    Unless you are doing more with the header, client.Post (or the package
    wide http.Post), does all you need: resp, err := http.Post(posturl,
    "application/json", bytes.NewReader(data))

    I'm not saying it's more idiomatic, but since there are functions/methods
    that more precisely do what you want, you should probably use them. For me,
    saving lines of code and being more readable *is* more idiomatic for go,
    but I consider the later (readability) more important than the former.

    On Wednesday, September 18, 2013 10:41:58 AM UTC-7, Brady.S...@iwsinc.comwrote:
    https://gist.github.com/bradysullivan/6612701

    I know there is a simple, more concise way to go about what I am doing.
    Specifically posting the parameters in json, with the appropriate header.

    Anyone have thoughts as to how to I can do this more idiomatically?

    The information contained in this transmission contains potentially
    privileged, export controlled and/or confidential information of
    Imageware Systems, Inc. or its customers or partners. It is intended only
    to be read by the person(s) named above and for no other purpose. You
    are hereby notified that any dissemination, distribution, duplication of
    this communication or use of its contents for any purpose not authorized
    expressly by Imageware Systems, Inc. is strictly prohibited and could
    lead to both civil and/or criminal penalties. If you are not the intended
    recipient, you are prohibited to review the contents herein and please
    contact the sender by reply e-mail and destroy all copies of the original
    message. To reply to our e-mail administrator directly, please send an
    e-mail to email...@iwsinc.com
    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Carlos Castillo at Sep 21, 2013 at 11:09 pm
    Although it's hard to tell from the documentation, passing a "https://*"
    URL to one of the http.Client methods makes a SSL connection. Unless you
    are using some custom SSL configuration, you should just be able to use
    client.Post. If you don't need a custom client, meaning that
    DefaultTransport does what you need in a RoundTripper (handle standard
    SSL), you don't need any advanced Redirect logic (default: stop at 10
    hops), and you aren't expecting to use cookies, then the package wide
    http.Post is one step faster than creating a client and using its Post
    method.

    On Sat, Sep 21, 2013 at 3:46 PM, Brady Sullivan wrote:

    Thanks Carlos, those are exactly the comments I was looking for. The only
    problem with combining it into http.Post is I need to use SSL. So right now
    I am creating a transport, a client, and calling the request with client.Do
    in order to use SSL. Is there another way that you know of?

    On Friday, September 20, 2013 2:55:40 PM UTC-7, Carlos Castillo wrote:

    On line 6, you can use bytes.NewReader instead of converting the data to
    a string and using strings.NewReader. This is clearer, shorter, and
    prevents making an extra copy of the data (ie: faster & less mem).

    Unless you are doing more with the header, client.Post (or the package
    wide http.Post), does all you need: resp, err := http.Post(posturl,
    "application/json", bytes.NewReader(data))

    I'm not saying it's more idiomatic, but since there are functions/methods
    that more precisely do what you want, you should probably use them. For me,
    saving lines of code and being more readable *is* more idiomatic for go,
    but I consider the later (readability) more important than the former.

    On Wednesday, September 18, 2013 10:41:58 AM UTC-7, Brady.S...@iwsinc.comwrote:
    https://gist.github.com/**bradysullivan/6612701<https://gist.github.com/bradysullivan/6612701>

    I know there is a simple, more concise way to go about what I am doing.
    Specifically posting the parameters in json, with the appropriate header.

    Anyone have thoughts as to how to I can do this more idiomatically?

    The information contained in this transmission contains potentially
    privileged, export controlled and/or confidential information of
    Imageware Systems, Inc. or its customers or partners. It is intended only
    to be read by the person(s) named above and for no other purpose. You
    are hereby notified that any dissemination, distribution, duplication of
    this communication or use of its contents for any purpose not
    authorized expressly by Imageware Systems, Inc. is strictly prohibited
    and could lead to both civil and/or criminal penalties. If you are not the
    intended recipient, you are prohibited to review the contents herein
    and please contact the sender by reply e-mail and destroy all copies of the original
    message. To reply to our e-mail administrator directly, please send an
    e-mail to email...@iwsinc.com
    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/2snJQkwFm_Q/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Carlos Castillo

    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brady Sullivan at Sep 21, 2013 at 11:30 pm
    That's awesome actually. Yeah, it's just default shit. Is this in the docs
    because I remember it pointing me at making a transport?
    On Saturday, September 21, 2013 4:08:58 PM UTC-7, Carlos Castillo wrote:

    Although it's hard to tell from the documentation, passing a "https://*"
    URL to one of the http.Client methods makes a SSL connection. Unless you
    are using some custom SSL configuration, you should just be able to use
    client.Post. If you don't need a custom client, meaning that
    DefaultTransport does what you need in a RoundTripper (handle standard
    SSL), you don't need any advanced Redirect logic (default: stop at 10
    hops), and you aren't expecting to use cookies, then the package wide
    http.Post is one step faster than creating a client and using its Post
    method.


    On Sat, Sep 21, 2013 at 3:46 PM, Brady Sullivan <br...@bsull.com<javascript:>
    wrote:
    Thanks Carlos, those are exactly the comments I was looking for. The only
    problem with combining it into http.Post is I need to use SSL. So right now
    I am creating a transport, a client, and calling the request with client.Do
    in order to use SSL. Is there another way that you know of?

    On Friday, September 20, 2013 2:55:40 PM UTC-7, Carlos Castillo wrote:

    On line 6, you can use bytes.NewReader instead of converting the data to
    a string and using strings.NewReader. This is clearer, shorter, and
    prevents making an extra copy of the data (ie: faster & less mem).

    Unless you are doing more with the header, client.Post (or the package
    wide http.Post), does all you need: resp, err := http.Post(posturl,
    "application/json", bytes.NewReader(data))

    I'm not saying it's more idiomatic, but since there are
    functions/methods that more precisely do what you want, you should probably
    use them. For me, saving lines of code and being more readable *is* more
    idiomatic for go, but I consider the later (readability) more important
    than the former.

    On Wednesday, September 18, 2013 10:41:58 AM UTC-7,
    Brady.S...@iwsinc.com wrote:
    https://gist.github.com/**bradysullivan/6612701<https://gist.github.com/bradysullivan/6612701>

    I know there is a simple, more concise way to go about what I am doing.
    Specifically posting the parameters in json, with the appropriate header.

    Anyone have thoughts as to how to I can do this more idiomatically?

    The information contained in this transmission contains potentially
    privileged, export controlled and/or confidential information of
    Imageware Systems, Inc. or its customers or partners. It is intended only
    to be read by the person(s) named above and for no other purpose. You
    are hereby notified that any dissemination, distribution, duplication of
    this communication or use of its contents for any purpose not
    authorized expressly by Imageware Systems, Inc. is strictly prohibited
    and could lead to both civil and/or criminal penalties. If you are not the
    intended recipient, you are prohibited to review the contents herein
    and please contact the sender by reply e-mail and destroy all copies of the original
    message. To reply to our e-mail administrator directly, please send an
    e-mail to email...@iwsinc.com
    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/2snJQkwFm_Q/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Carlos Castillo
    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 18, '13 at 6:37p
activeSep 21, '13 at 11:30p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase