阅读背景:

go 练习:HTTP 处理

来源:互联网 

这篇文章只是联系go指南时的笔记吧。

package main import ( "fmt" "log" "net/http" ) type String string type Struct struct{ Greeting string Punct string Who string } func main(){ http.Handle("/string",String("aaaaaaaaaaaaaaaaaaaa2")) http.Handle("/struct", Struct{ Greeting: "Hello", Punct: "", Who: "gopher", }) log.Fatal(http.ListenAndServe("localhost:4000",nil)) } 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) } package main import ( "fmt" "lo



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: