Reputation: 22879
I'm running a script which opens an http port. I initially had it logging errors:
log.Fatal(http.ListenAndServe(":7777", router))
I have additional code so I want to run it on another thread:
go http.ListenAndServe(":7777", router)
I still want to log any information related to the http port failing, but neither work:
go log.Fatal(http.ListenAndServe(":7777", router))
Or
log.Fatal(go http.ListenAndServe(":7777", router))
What is the correct syntax for this?
Upvotes: 1
Views: 703
Reputation: 928
You can wrap it in an anonymous function:
go func() {
log.Fatal(http.ListenAndServe(":7777", router))
}()
Upvotes: 6