Implement the following types and define Servehttp methods on them. Register them to handle specific paths in your Web server.
Type string stringtype struct struct { greeting string punct string who string}
For example, you should is able to register handlers using:
http. Handle ("/string", String ("I ' m a frayed knot.")) http. Handle ("/struct", &struct{"Hello", ":", "gophers!"})
Package Mainimport ("net/http" "FMT") Type Stringstringtype Structstruct{GreetingstringpunctstringW.H.O.string}func (H Struct) servehttp (w http. Responsewriter, R*http. Request) {fmt. Fprint (W, h)}func (S String) servehttp (w http. Responsewriter, R*http. Request) {fmt. Fprint (W, s)}func main () {http. Handle ("/string", String ("I ' m a frayed knot.") ) http. Handle ("/struct", &struct{"Hello",":","gophers!"}) //your HTTP. Handle calls herehttp. Listenandserve ("localhost:4000", nil)}
A Tour of Go exercise:http handlers