]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add example for StructTag
authorKamil Kisiel <kamil@kamilkisiel.net>
Mon, 23 Sep 2013 17:19:08 +0000 (13:19 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 23 Sep 2013 17:19:08 +0000 (13:19 -0400)
Fix a few minor vet quibbles while I'm here.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13235059

src/pkg/reflect/all_test.go
src/pkg/reflect/example_test.go

index 137628624601c3e08060edd275d8b7ccd4c03fe0..a2f639fcc41ec5b6acf5660582e72247c367ca34 100644 (file)
@@ -948,7 +948,7 @@ func TestMap(t *testing.T) {
 
        newm := newmap.Interface().(map[string]int)
        if len(newm) != len(m) {
-               t.Errorf("length after copy: newm=%d, m=%d", newm, m)
+               t.Errorf("length after copy: newm=%d, m=%d", len(newm), len(m))
        }
 
        for k, v := range newm {
@@ -3478,7 +3478,7 @@ func TestAllocsInterfaceBig(t *testing.T) {
        }
        v := ValueOf(S{})
        if allocs := testing.AllocsPerRun(100, func() { v.Interface() }); allocs > 0 {
-               t.Errorf("allocs:", allocs)
+               t.Error("allocs:", allocs)
        }
 }
 
@@ -3495,7 +3495,7 @@ func TestAllocsInterfaceSmall(t *testing.T) {
        }
        v := ValueOf(int64(0))
        if allocs := testing.AllocsPerRun(100, func() { v.Interface() }); allocs > 0 {
-               t.Errorf("allocs:", allocs)
+               t.Error("allocs:", allocs)
        }
 }
 
index 62455c00ad9447e12b28be9e8b3e97d62dd65885..cca28eeece8c2b994735d33ddcf603a27680ea73 100644 (file)
@@ -50,3 +50,17 @@ func ExampleMakeFunc() {
        // 1 0
        // 3.14 2.72
 }
+
+func ExampleStructTag() {
+       type S struct {
+               F string `species:"gopher" color:"blue"`
+       }
+
+       s := S{}
+       st := reflect.TypeOf(s)
+       field := st.Field(0)
+       fmt.Println(field.Tag.Get("color"), field.Tag.Get("species"))
+
+       // Output:
+       // blue gopher
+}