struct的tag到底可以用来做什么?

在Go的spec文件里面针对tag有一些介绍 https://golang.org/ref/spec#Struct_types

A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. An empty tag string is equivalent to an absent tag. The tags are made visible through a reflection interface and take part in type identity for structs but are otherwise ignored.

struct {
    x, y float64 ""  // an empty tag string is like an absent tag
    name string  "any string is permitted as a tag"
    _    [4]byte "ceci n'est pas un champ de structure"
}

// A struct corresponding to a TimeStamp protocol buffer.
// The tag strings define the protocol buffer field numbers;
// they follow the convention outlined by the reflect package.
struct {
    microsec  uint64 `protobuf:"1"`
    serverIP6 uint64 `protobuf:"2"`
}

这个文字解释其实很短,也没有很详细的介绍这个到底可以用来做什么?大家知道这个tag到底可以用来做什么?怎么用?

已邀请:

youEclipse - 想换工作啊

赞同来自:

要回复问题请先登录注册