]> Cypherpunks repositories - gostls13.git/commit
reflect: support for struct tag use by multiple packages
authorRuss Cox <rsc@golang.org>
Wed, 29 Jun 2011 13:52:34 +0000 (09:52 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 29 Jun 2011 13:52:34 +0000 (09:52 -0400)
commit25733a94fde4f4af4b6ac5ba01b7212a3ef0f013
treec9ed4ef95dce4a6654bba7b32c1c8b35d713cdec
parentf83609f642fc995a48de3ed8742c12ee4779d3a4
reflect: support for struct tag use by multiple packages

Each package using struct field tags assumes that
it is the only package storing data in the tag.
This CL adds support in package reflect for sharing
tags between multiple packages.  In this scheme, the
tags must be of the form

        key:"value" key2:"value2"

(raw strings help when writing that tag in Go source).

reflect.StructField's Tag field now has type StructTag
(a string type), which has method Get(key string) string
that returns the associated value.

Clients of json and xml will need to be updated.
Code that says

        type T struct {
                X int "name"
        }

should become

        type T struct {
                X int `json:"name"`  // or `xml:"name"`
        }

Use govet to identify struct tags that need to be changed
to use the new syntax.

R=r, r, dsymonds, bradfitz, kevlar, fvbommel, n13m3y3r
CC=golang-dev
https://golang.org/cl/4645069
24 files changed:
src/cmd/godoc/codewalk.go
src/cmd/govet/govet.go
src/pkg/asn1/asn1.go
src/pkg/asn1/asn1_test.go
src/pkg/asn1/marshal.go
src/pkg/asn1/marshal_test.go
src/pkg/crypto/ocsp/ocsp.go
src/pkg/crypto/x509/pkix/pkix.go
src/pkg/crypto/x509/x509.go
src/pkg/go/types/testdata/exports.go
src/pkg/json/decode.go
src/pkg/json/decode_test.go
src/pkg/json/encode.go
src/pkg/net/dnsmsg.go
src/pkg/reflect/all_test.go
src/pkg/reflect/type.go
src/pkg/rpc/jsonrpc/all_test.go
src/pkg/rpc/jsonrpc/client.go
src/pkg/rpc/jsonrpc/server.go
src/pkg/xml/embed_test.go
src/pkg/xml/marshal.go
src/pkg/xml/marshal_test.go
src/pkg/xml/read.go
src/pkg/xml/read_test.go