FAQ
In the below code, "hello" is called twice when I accessed to
http://localhost:8080. why?

package main

import (
"fmt"
"net/http"
)

func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("hello")
}

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

  • Dave Cheney at Mar 22, 2013 at 11:17 am
    Your browser is requesting /favicon.ico, this matches the catchall
    handler, "/" so you get called twice.
    On Fri, Mar 22, 2013 at 10:14 PM, kawamoto wrote:
    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

    --
    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.
    --
    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.
  • Jan Mercl at Mar 22, 2013 at 11:20 am

    On Fri, Mar 22, 2013 at 12:17 PM, Dave Cheney wrote:
    Your browser is requesting /favicon.ico, this matches the catchall
    handler, "/" so you get called twice.
    I think this is a FAQ candidate.

    -j

    --
    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.
  • Scott Lawrence at Mar 22, 2013 at 11:19 am
    If you log the request, you'll see your browser is probably also requesting
    /favicon.ico, which is being passed to that same handler.
    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013 x86_64 GNU/Linux

    --
    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.
  • Yasutaka Kawamoto at Mar 22, 2013 at 11:57 am
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <bytbox@gmail.com>:
    If you log the request, you'll see your browser is probably also requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013 x86_64
    GNU/Linux
    --
    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.
  • Nvcnvn at Mar 22, 2013 at 12:14 pm
    func main() {
    http.HandleFunc("/favicon.ico", handlerICon)
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    Vào 18:57:21 UTC+7 Thứ sáu, ngày 22 tháng ba năm 2013, kawamoto đã viết:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com <javascript:>>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013 x86_64
    GNU/Linux
    --
    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.
  • Yasutaka Kawamoto at Mar 22, 2013 at 12:27 pm
    Oh... I see.
    I could run in below code.

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/favicon.ico", handlerICon)
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)

    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

    func handlerICon(w http.ResponseWriter, r *http.Request) {}


    Thanks!


    2013/3/22 nvcnvn <nvcnvn1@gmail.com>:
    func main() {
    http.HandleFunc("/favicon.ico", handlerICon)
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    Vào 18:57:21 UTC+7 Thứ sáu, ngày 22 tháng ba năm 2013, kawamoto đã viết:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013
    x86_64
    GNU/Linux
    --
    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.
    --
    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.
  • Jeremy Wall at Mar 22, 2013 at 4:12 pm
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.

    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto wrote:

    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <bytbox@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013 x86_64
    GNU/Linux
    --
    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.

    --
    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.
  • Yasutaka Kawamoto at Mar 22, 2013 at 4:47 pm
    I got it.

    When I don't write "http.HandleFunc("/favicon.ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jwall@google.com>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.

    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto wrote:

    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <bytbox@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013
    x86_64
    GNU/Linux
    --
    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.
    --
    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.
  • Jason at Mar 25, 2013 at 6:54 pm
    I have a meta-question: Why is "/" a catch-all URL instead of "" (or almost
    anything else)? This also bit me when I wrote a "/" handler, and I expect
    it's common for someone to write a specific handler for their HTTP server
    home page. There doesn't seem to be a way to specify that special handler,
    though.
    On Friday, March 22, 2013 12:47:55 PM UTC-4, kawamoto wrote:

    I got it.

    When I don't write "http.HandleFunc("/favicon.ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jw...@google.com <javascript:>>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.

    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto wrote:

    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com <javascript:>>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET 2013
    x86_64
    GNU/Linux
    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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.
  • Atomly at Mar 25, 2013 at 6:58 pm

    On Mon, Mar 25, 2013 at 2:54 PM, Jason wrote:

    I have a meta-question: Why is "/" a catch-all URL instead of "" (or
    almost anything else)? This also bit me when I wrote a "/" handler, and I
    expect it's common for someone to write a specific handler for their HTTP
    server home page. There doesn't seem to be a way to specify that special
    handler, though.
    Yeah, it feels like it should be "/*" or "*" or something, with "/"
    specifically referring to "/" and only "/"...

    :: atomly ::

    [ atomly@atomly.com : www.atomly.com : http://blog.atomly.com/ ...
    [ atomiq records : new york city : +1.347.692.8661 ...
    [ e-mail atomly-news-subscribe@atomly.com for atomly info and updates ...


    On Friday, March 22, 2013 12:47:55 PM UTC-4, kawamoto wrote:

    I got it.

    When I don't write "http.HandleFunc("/favicon.**ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jw...@google.com>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.


    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto <kwm...@gmail.com>
    wrote:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET
    2013
    x86_64
    GNU/Linux
    --
    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...@**googlegroups.com.
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>.
    --
    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.

    --
    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.
  • Liigo Zhuang at Mar 26, 2013 at 8:06 am
    +1
    在 2013-3-26 上午2:58,"atomly" <atomly@gmail.com>写道:
    On Mon, Mar 25, 2013 at 2:54 PM, Jason wrote:

    I have a meta-question: Why is "/" a catch-all URL instead of "" (or
    almost anything else)? This also bit me when I wrote a "/" handler, and I
    expect it's common for someone to write a specific handler for their HTTP
    server home page. There doesn't seem to be a way to specify that special
    handler, though.
    Yeah, it feels like it should be "/*" or "*" or something, with "/"
    specifically referring to "/" and only "/"...

    :: atomly ::

    [ atomly@atomly.com : www.atomly.com : http://blog.atomly.com/ ...
    [ atomiq records : new york city : +1.347.692.8661 ...
    [ e-mail atomly-news-subscribe@atomly.com for atomly info and updates ...


    On Friday, March 22, 2013 12:47:55 PM UTC-4, kawamoto wrote:

    I got it.

    When I don't write "http.HandleFunc("/favicon.**ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jw...@google.com>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.


    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto <kwm...@gmail.com>
    wrote:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET
    2013
    x86_64
    GNU/Linux
    --
    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...@**googlegroups.com.
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>.
    --
    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.

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

    --
    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.
  • Karaziox at Mar 25, 2013 at 9:47 pm
    Because when you request a page in http the minimum request is : GET /
    HTTP/1.1
    IMHO, since / is the root of your server in http, they used that naming for
    the handler too.
    On Monday, March 25, 2013 2:54:55 PM UTC-4, Jason wrote:

    I have a meta-question: Why is "/" a catch-all URL instead of "" (or
    almost anything else)? This also bit me when I wrote a "/" handler, and I
    expect it's common for someone to write a specific handler for their HTTP
    server home page. There doesn't seem to be a way to specify that special
    handler, though.
    On Friday, March 22, 2013 12:47:55 PM UTC-4, kawamoto wrote:

    I got it.

    When I don't write "http.HandleFunc("/favicon.ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jw...@google.com>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.


    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto <kwm...@gmail.com>
    wrote:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET
    2013
    x86_64
    GNU/Linux
    --
    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...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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.
  • Jason at Mar 26, 2013 at 12:12 am
    Well, sure, but that specifies a resource (the root resource). Why should
    it stand in for:

    /
    /favicon.ico
    /foo/bar

    etc.?
    On Monday, March 25, 2013 3:00:37 PM UTC-4, kara...@gmail.com wrote:

    Because when you request a page in http the minimum request is : GET /
    HTTP/1.1
    IMHO, since / is the root of your server in http, they used that naming
    for the handler too.
    On Monday, March 25, 2013 2:54:55 PM UTC-4, Jason wrote:

    I have a meta-question: Why is "/" a catch-all URL instead of "" (or
    almost anything else)? This also bit me when I wrote a "/" handler, and I
    expect it's common for someone to write a specific handler for their HTTP
    server home page. There doesn't seem to be a way to specify that special
    handler, though.
    On Friday, March 22, 2013 12:47:55 PM UTC-4, kawamoto wrote:

    I got it.

    When I don't write "http.HandleFunc("/favicon.ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jw...@google.com>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.


    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto <kwm...@gmail.com>
    wrote:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET
    2013
    x86_64
    GNU/Linux
    --
    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...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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.
  • Brad Fitzpatrick at Mar 26, 2013 at 3:44 pm
    This is https://code.google.com/p/go/issues/detail?id=4799
    On Mon, Mar 25, 2013 at 11:54 AM, Jason wrote:

    I have a meta-question: Why is "/" a catch-all URL instead of "" (or
    almost anything else)? This also bit me when I wrote a "/" handler, and I
    expect it's common for someone to write a specific handler for their HTTP
    server home page. There doesn't seem to be a way to specify that special
    handler, though.

    On Friday, March 22, 2013 12:47:55 PM UTC-4, kawamoto wrote:

    I got it.

    When I don't write "http.HandleFunc("/favicon.**ico", handlerICon)" and
    I hit the url with curl,
    I checked it only gets once.

    Thank you for the information.

    2013/3/23 Jeremy Wall <jw...@google.com>:
    if you just want to verify it only gets called once you can always hit the
    url with curl which won't generate extra http requrests for you.


    On Fri, Mar 22, 2013 at 6:57 AM, Yasutaka Kawamoto <kwm...@gmail.com>
    wrote:
    Thanks All

    I got.

    I use Google Chrome.
    How do you avoid it?


    2013/3/22 Scott Lawrence <byt...@gmail.com>:
    If you log the request, you'll see your browser is probably also
    requesting
    /favicon.ico, which is being passed to that same handler.

    On Fri, 22 Mar 2013, kawamoto wrote:

    In the below code, "hello" is called twice when I accessed to
    http://localhost:8080. why?

    package main

    import (
    "fmt"
    "net/http"
    )

    func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
    }

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("hello")
    }

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

    go version go1.0.3
    Linux baidar 3.8.3-2-ARCH #1 SMP PREEMPT Sun Mar 17 13:04:22 CET
    2013
    x86_64
    GNU/Linux
    --
    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...@**googlegroups.com.
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>.
    --
    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.

    --
    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
postedMar 22, '13 at 11:14a
activeMar 26, '13 at 3:44p
posts15
users11
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase