FAQ
I am trying to implement a general function to POST data.I got a
io.Reader,and want to support url-encoded and json-encoded (and other often
used type possible).I want to peek the first part instead of the whole,of
reader to judge the encoded format and set proper Content-Type.Does regexp
only works fine or do I need write some hand-write parser?

--
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/d/optout.

Search Discussions

  • Tamás Gulácsi at Feb 12, 2015 at 5:50 am
    Json should start with { or [, and end with the pair of it.
    If that is enough, you can use bufio.Buffer, and its Peek method to check the beginning.

    --
    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/d/optout.
  • Viktor Kojouharov at Feb 12, 2015 at 6:35 pm
    That doesn't seem to be correct. 'value's can also be top-level in a json,
    such as `"test"` or `false`
    On Thursday, February 12, 2015 at 7:50:30 AM UTC+2, Tamás Gulácsi wrote:

    Json should start with { or [, and end with the pair of it.
    If that is enough, you can use bufio.Buffer, and its Peek method to check
    the beginning.
    --
    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/d/optout.
  • Gao at Feb 13, 2015 at 12:14 pm
    Is that to say there is no way to tell json-encoded and url-encoded
    format,and it should be set by hand?
    On Friday, February 13, 2015 at 2:35:16 AM UTC+8, Viktor Kojouharov wrote:

    That doesn't seem to be correct. 'value's can also be top-level in a json,
    such as `"test"` or `false`
    On Thursday, February 12, 2015 at 7:50:30 AM UTC+2, Tamás Gulácsi wrote:

    Json should start with { or [, and end with the pair of it.
    If that is enough, you can use bufio.Buffer, and its Peek method to check
    the beginning.
    --
    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/d/optout.
  • Alex Zylman at Feb 13, 2015 at 6:49 am
    You shouldn't do this by "peek"ing at the body, you should do this by
    examining the "Content-type" header and parsing the body based on the
    header.
    On Wednesday, February 11, 2015 at 5:47:16 PM UTC-10, Gao wrote:

    I am trying to implement a general function to POST data.I got a
    io.Reader,and want to support url-encoded and json-encoded (and other often
    used type possible).I want to peek the first part instead of the whole,of
    reader to judge the encoded format and set proper Content-Type.Does regexp
    only works fine or do I need write some hand-write parser?
    --
    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/d/optout.
  • Alex Zylman at Feb 13, 2015 at 6:50 am
    You shouldn't do this by "peek"ing at the body, you should do this by
    looking at the "Content-type" header and deciding how to parse the body
    based on that.
    On Wednesday, February 11, 2015 at 5:47:16 PM UTC-10, Gao wrote:

    I am trying to implement a general function to POST data.I got a
    io.Reader,and want to support url-encoded and json-encoded (and other often
    used type possible).I want to peek the first part instead of the whole,of
    reader to judge the encoded format and set proper Content-Type.Does regexp
    only works fine or do I need write some hand-write parser?
    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 12, '15 at 3:47a
activeFeb 13, '15 at 12:14p
posts6
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase