FAQ
hi all
i implementation subrouter in project
my subrouter is :
mag.localhost:4444

and i have many handler in project for example help.
if i call mag.localhost:4444 all things is ok
for e.g:
if i call mag.localhost:4444/help it called help handler ! why?

localhost ip -> 127.0.0.1
mag.localhost ip -> 127.0.0.20

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

  • Myalexer at Apr 11, 2015 at 5:54 pm
    nobody?

    --
    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.
  • Egon at Apr 11, 2015 at 6:15 pm

    On Saturday, 7 March 2015 14:38:37 UTC+2, myal...@gmail.com wrote:
    hi all
    i implementation subrouter in project
    my subrouter is :
    mag.localhost:4444

    and i have many handler in project for example help.
    if i call mag.localhost:4444 all things is ok
    for e.g:
    if i call mag.localhost:4444/help it called help handler ! why?

    localhost ip -> 127.0.0.1
    mag.localhost ip -> 127.0.0.20
    Use play.golang.org or something to show a minimal reproducible test-case.

    It's hard to understand what might be wrong.
    It's even hard to understand what do you expect to happen.

    The answers you get depend highly how well your initial question is
    formulated and how well you explain the problem at hand (also how
    complicated the actual problem is).

    + Egon

    --
    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.
  • Myalexer at Apr 11, 2015 at 7:00 pm
    i add 127.0.1.0 test.localhost to hosts file in system32 - code:
    package main

    import (
    "fmt"
    "net/http"
             "github.com/gorilla/mux"
    )

    func main() {
         m := mux.NewRouter()
         s := m.Host("mag.localhost").Subrouter()
         s.HandleFunc("/",TestHandler)
         m.HandleFunc("/help",Help)
         http.Handle("/",m)
         http.ListenAndServe(":4444",m)
    }

    func TestHandler(W http.ResponseWriter,Req *http.Request){
    fmt.Fprintln(W,"Ok")
    }
    func Help(W http.ResponseWriter ,Req *http.Request){
             fmt.Fprintln(w,"help")
    }

    --
    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.
  • Chris dollin at Apr 11, 2015 at 7:26 pm
    Tell us what the problem is -- what did you do, what did you
    expect, what did you see happen.

    I note that the code above isn't the code you actually ran,
    since it doesn't compile. Make sure you're really really
    posting the code you're using.

    I also note that your router has host 'mag.localhost' but that
    you say that you've added 'test.localhost'.

    I suspect (I'm not a gorilla expert) that if a subrouter doesn't
    match a route then the other routers get a chance to look
    at the path. But I don't know for sure.

    Chris

    On 11 April 2015 at 20:00, wrote:
    i add 127.0.1.0 test.localhost to hosts file in system32 - code:
    package main

    import (
    "fmt"
    "net/http"
    "github.com/gorilla/mux"
    )

    func main() {
    m := mux.NewRouter()
    s := m.Host("mag.localhost").Subrouter()
    s.HandleFunc("/",TestHandler)
    m.HandleFunc("/help",Help)
    http.Handle("/",m)
    http.ListenAndServe(":4444",m)
    }

    func TestHandler(W http.ResponseWriter,Req *http.Request){
    fmt.Fprintln(W,"Ok")
    }
    func Help(W http.ResponseWriter ,Req *http.Request){
    fmt.Fprintln(w,"help")
    }

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


    --
    Chris "allusive" Dollin

    --
    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.
  • Egon at Apr 11, 2015 at 8:07 pm
    The reason it matches help is because "/help" matches all domains, and
    there is no match inside the sub-router; this means it uses the match it
    has.
    On Saturday, 11 April 2015 22:00:04 UTC+3, myal...@gmail.com wrote:

    i add 127.0.1.0 test.localhost to hosts file in system32 - code:
    package main

    import (
    "fmt"
    "net/http"
    "github.com/gorilla/mux"
    )

    func main() {
    m := mux.NewRouter()
    s := m.Host("mag.localhost").Subrouter()
    s.HandleFunc("/",TestHandler)
    m.HandleFunc("/help",Help)
    http.Handle("/",m)
    http.ListenAndServe(":4444",m)
    }

    func TestHandler(W http.ResponseWriter,Req *http.Request){
    fmt.Fprintln(W,"Ok")
    }
    func Help(W http.ResponseWriter ,Req *http.Request){
    fmt.Fprintln(w,"help")
    }
    --
    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.
  • Myalexer at Apr 11, 2015 at 8:11 pm
    Thank you
    i am confused in this post :
    https://groups.google.com/forum/#!topic/golang-nuts/yF7KEX-Ze8M

    --
    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
postedMar 7, '15 at 12:38p
activeApr 11, '15 at 8:11p
posts7
users3
websitegolang.org

3 users in discussion

Myalexer: 4 posts Egon: 2 posts Chris dollin: 1 post

People

Translate

site design / logo © 2022 Grokbase