Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?



From 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)
   }




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: