3 ms·
Thanks! That's exactly what I was trying to figure out. You're a gem. So is there anywhere I can see an example of code that runs a server like this?
by tocomment 14y ago
Thanks! That's exactly what I was trying to figure out. You're a gem.
So is there anywhere I can see an example of code that runs a server like this?
- eckyptang 14y agoFrom the tour - I've added comments for clarity: // this defines the entry point package main // import formatting and HTTP server packages import ( "fmt" "net/http" ) // This is your HTTP Server instance type Hello struct{} // This is a method on your HTTP server instance that sends hello for all requests func (h Hello) ServeHTTP( w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello!") } // this is your entry point func main() { // create a new HTTP Server instance var h Hello // tell the runtime to serve it http.ListenAndServe("localhost:4000",h) }