來自net/http的源代碼。 http.Header
的定義是map[string][]string
。對?爲什麼http.Header中片的長度返回0?
但爲什麼go run
下面的代碼,我得到的結果是:
func main() {
var header = make(http.Header)
header.Add("hello", "world")
header.Add("hello", "anotherworld")
var t = []string {"a", "b"}
fmt.Printf("%d\n", len(header["hello"]))
fmt.Print(len(t))
}
如果你不確定你的結構的內容,請嘗試使用['%#v'(http://golang.org/pkg/fmt/ #打印)格式字符串,它可以很好地打印所有具有名稱的值。例子:['fmt.Printf(「%#v \ n」,header)'](http://play.golang.org/p/vZWWRiV_sQ) – nemo