FAQ
Hey guys,

So I've built a webserver in which I want to have a http.Handle that any
URL starting with http://www.mywebsite.com/download/ sends to the handle.

So I want the handler to match:

http://www.mywebsite.com/download/file.txt
http://www.mywebsite.com/download/other_stuff/another_file
...

Reading the ServerMux part of the http package, it seems to indicate that
as long as I don't register another longer URL, this one should match.
However, in the example below, the Handle I register will be called if I
put in:
http://www.mywebsite.com/download/

It will not answer (I'll get a 404) if I do:
http://www.mywebsite.com/download/file.txt

My registration code:
http.Handle("/download", http.HandlerFunc(func(w http.ResponseWriter, r
*http.Request){s.downloadHandler(w, r)}))

Can anyone point me at what I'm doing wrong here? The only other handler I
registered is "/".

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

Search Discussions

  • Minux at Jan 30, 2013 at 8:01 pm

    On Thu, Jan 31, 2013 at 3:58 AM, John wrote:

    Hey guys,

    So I've built a webserver in which I want to have a http.Handle that any
    URL starting with http://www.mywebsite.com/download/ sends to the handle.

    So I want the handler to match:

    http://www.mywebsite.com/download/file.txt
    http://www.mywebsite.com/download/other_stuff/another_file
    ...

    Reading the ServerMux part of the http package, it seems to indicate that
    as long as I don't register another longer URL, this one should match.
    However, in the example below, the Handle I register will be called if I
    put in:
    http://www.mywebsite.com/download/

    It will not answer (I'll get a 404) if I do:
    http://www.mywebsite.com/download/file.txt

    My registration code:
    http.Handle("/download", http.HandlerFunc(func(w http.ResponseWriter, r
    *http.Request){s.downloadHandler(w, r)}))
    http.Handle("/download/", ...) // if you want this handler to handle all
    files rooted at /download/
    Can anyone point me at what I'm doing wrong here? The only other handler
    I registered is "/".
    --
    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.
  • John Doak at Jan 30, 2013 at 9:24 pm
    Thanks minux.
    On Wed, Jan 30, 2013 at 12:00 PM, minux wrote:


    On Thu, Jan 31, 2013 at 3:58 AM, John wrote:

    Hey guys,

    So I've built a webserver in which I want to have a http.Handle that any
    URL starting with http://www.mywebsite.com/download/ sends to the handle.

    So I want the handler to match:

    http://www.mywebsite.com/download/file.txt
    http://www.mywebsite.com/download/other_stuff/another_file
    ...

    Reading the ServerMux part of the http package, it seems to indicate that
    as long as I don't register another longer URL, this one should match.
    However, in the example below, the Handle I register will be called if I
    put in:
    http://www.mywebsite.com/download/

    It will not answer (I'll get a 404) if I do:
    http://www.mywebsite.com/download/file.txt

    My registration code:
    http.Handle("/download", http.HandlerFunc(func(w http.ResponseWriter, r
    *http.Request){s.downloadHandler(w, r)}))
    http.Handle("/download/", ...) // if you want this handler to handle all
    files rooted at /download/
    Can anyone point me at what I'm doing wrong here? The only other handler
    I registered is "/".

    --
    John Doak
    http://flavors.me/johnsiilver

    --
    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
postedJan 30, '13 at 7:59p
activeJan 30, '13 at 9:24p
posts3
users2
websitegolang.org

2 users in discussion

John Doak: 2 posts Minux: 1 post

People

Translate

site design / logo © 2022 Grokbase