go-examples/example-httpserver/main.go

24 lines
379 B
Go
Raw Permalink Normal View History

2017-07-12 16:37:41 +00:00
package main
import (
"io"
"log"
"net/http"
)
type MyHandler int
func (MyHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.Header().Set("Content-Type", "text/plain")
2017-07-12 16:39:07 +00:00
io.WriteString(resp, req.RequestURI)
2017-07-12 16:37:41 +00:00
}
func main() {
var myHandler = new(MyHandler)
s := &http.Server{
Addr: ":9000",
Handler: myHandler,
}
log.Fatal(s.ListenAndServe())
}