This is a creation in Article, where the information may have evolved or changed.
Exercise: HTTP Processing
Implement the following type, and define the Servehttp method on it. Register them in the Web server to process the specified path.
Type string stringtype struct struct { greeting string punct string who string}
For example, you can register a processing method using the following methods:
http. Handle ("/string", String ("I ' m a frayed knot.")) http. Handle ("/struct", &struct{"Hello", ":", "gophers!"})
Package Mainimport ( "FMT" "Log" " net/http") type String stringtype struct struct { greeting string punct string who String}func (s string) servehttp (w http. Responsewriter, R *http. Request) { fmt. Fprint (W, s)}func (S Struct) 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!"}) Log. Fatal (http. Listenandserve ("localhost:4000", Nil))}