我刚开始学习Go语言,正在查看它们的教程(https://golang.org/doc/code.html)。
在其中的一个例子中,他们将一个变量设置为结构体,但是我很困惑他们如何在下面的for循环中访问结构体的成员?有没有人可以澄清一下?非常感谢!
代码:
package stringutil
import "testing"
func TestReverse(t *testing.T) {
cases := []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"Hello, 世界", "界世 ,olleH"},
{"", ""},
}
for _, c := range cases {
got := Reverse(c.in)
if got != c.want {
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
}
}
}