Skip to content

Instantly share code, notes, and snippets.

@fwojciec
Last active July 23, 2018 10:49
Show Gist options
  • Save fwojciec/e89cbd6056064c67ca5ac3f15284b54c to your computer and use it in GitHub Desktop.
Save fwojciec/e89cbd6056064c67ca5ac3f15284b54c to your computer and use it in GitHub Desktop.
My solution to "Exercise Hello, Handler" from Section 02 of Francesc Campoy's Go Web Workshop
// https://github.com/campoy/go-web-workshop/blob/master/section02/README.md
package main
import (
"fmt"
"log"
"net/http"
)
type helloHandler struct {
who string
}
func (h helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s", h.who)
}
func main() {
http.Handle("/hello", &helloHandler{who: "web"})
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment