Skip to content

reflect: convention for multiple packages using struct tags #1704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
niemeyer opened this issue Apr 14, 2011 · 1 comment
Closed

reflect: convention for multiple packages using struct tags #1704

niemeyer opened this issue Apr 14, 2011 · 1 comment

Comments

@niemeyer
Copy link
Contributor

== Problem ==

Tags may be used by multiple packages, and there's no convention today
to enable them to namespace their use so that they can obtain the
information they need while still allowing the struct tag to be used
by other packages.

This means a struct may have to be declared twice with exactly the
same fields, but with differing tags, to satisfy the needs of
different packages.


== Suggested solution ==

Establish a loose convention so that tags can optionally include
namespaces in the form NS(value) separated by spaces.  In the absence
of any namespaces (no '(' in the tag string), the whole tag value
continues to be taken into account.

As an example, the json package would be enhanced so that the
marshalling of JSON values specifically would make this:

   type T struct { F int "BEFORE KEY(name) AFTER" }

is equivalent to this:

   type T struct { F int "name" }

and this:

   type T struct { F int "OTHER(name)" }

is equivalent to this:

   type T struct { F int "" }


== Optional reflect enhancement ==

Optionally, the reflect package could receive a new function:

   func ParseTag(ns, tag string) string

This would handle the semantics defined above.
@dsymonds
Copy link
Contributor

Comment 2:

I believe this is done and implemented now, though with a different syntax.
http://code.google.com/p/go/source/detail?r=1dd08cd96bc3b32246b14f6cc58f0c53bf393f51

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants