Last active
July 23, 2018 10:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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