http.ListenAndServeis a blocking call. If you want to do another job (for example, make a second call http.ListenAndServe), you need to move it to a separate goroutine. That is all they do here.
select{} , goroutine, http.ListenAndServe goroutines. select{}, , main() .
, select{} go func() . , , .
.
. :
func main() {
http.HandleFunc("/", responsehandler.Handler)
go func() {
http.ListenAndServe(":8888", nil)
}()
fileservice.NewWatcher()
}
http.ListenAndServe, fileservice.NewWatcher() ( ). goroutine, fileservice.NewWatcher() .
- :
func init() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
}
- . , goroutine, init , . import _ "profiling" " " - .