Skip to content

the http handler executed twice?! #1298

@gopherbot

Description

@gopherbot

by shawn.hek:

i just write a simple program as follow:
import (
    "http"
    "fmt"
)

var counter int;

func handler(w http.ResponseWriter, r *http.Request) {
    counter++
    fmt.Printf("%d\n", counter)
}

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

but the console output confused me--every time i open the url in the browser, it outputs
twice like
0
1 // 1st
2
3 // 2nd
and so on

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions