2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-07 09:20:22 +00:00
cheat.sheets/sheets/go/http
2017-05-08 20:27:00 +00:00

26 lines
507 B
Plaintext

package main
import (
"fmt"
"net/http"
)
// define a type for the response
type Hello struct{}
// let that type implement the ServeHTTP method (defined in interface http.Handler)
func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello!")
}
func main() {
var h Hello
http.ListenAndServe("localhost:4000", h)
}
// Here's the method signature of http.ServeHTTP:
// type Handler interface {
// ServeHTTP(w http.ResponseWriter, r *http.Request)
// }