本文整理汇总了Golang中limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.GetField方法的典型用法代码示例。如果您正苦于以下问题:Golang Descriptor.GetField方法的具体用法?Golang Descriptor.GetField怎么用?Golang Descriptor.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor
的用法示例。
在下文中一共展示了Descriptor.GetField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: populateMessage
func (g *gensql) populateMessage(file *generator.FileDescriptor, msg *generator.Descriptor) {
model := limbo.GetModel(msg)
model.MessageType = "." + file.GetPackage() + "." + msg.GetName()
{ // default scanner
var found bool
for _, scanner := range model.Scanner {
if scanner.Name == "" {
found = true
break
}
}
if !found {
model.Scanner = append(model.Scanner, &limbo.ScannerDescriptor{Fields: "*"})
}
}
for _, scanner := range model.Scanner {
scanner.MessageType = "." + file.GetPackage() + "." + msg.GetName()
}
for _, field := range msg.GetField() {
if column := limbo.GetColumn(field); column != nil {
column.MessageType = "." + file.GetPackage() + "." + msg.GetName()
column.FieldName = field.GetName()
if column.Name == "" {
column.Name = field.GetName()
}
model.Column = append(model.Column, column)
}
if join := limbo.GetJoin(field); join != nil {
if field.GetType() != pb.FieldDescriptorProto_TYPE_MESSAGE {
g.gen.Fail(field.GetName(), "in", msg.GetName(), "must be a message")
}
join.MessageType = "." + file.GetPackage() + "." + msg.GetName()
join.FieldName = field.GetName()
join.ForeignMessageType = field.GetTypeName()
if join.Name == "" {
join.Name = field.GetName()
}
if join.Key == "" {
join.Key = field.GetName() + "_id"
}
if join.ForeignKey == "" {
join.ForeignKey = "id"
}
model.Join = append(model.Join, join)
}
}
sort.Sort(limbo.SortedColumnDescriptors(model.Column))
sort.Sort(limbo.SortedJoinDescriptors(model.Join))
sort.Sort(limbo.SortedScannerDescriptors(model.Scanner))
}
示例2: messageToSchema
func (g *jsonschema) messageToSchema(file *generator.FileDescriptor, desc *generator.Descriptor) (interface{}, []string) {
typeName := file.GetPackage() + "." + strings.Join(desc.TypeName(), ".")
typeName = strings.TrimPrefix(typeName, ".")
title := desc.TypeName()[len(desc.TypeName())-1]
var (
dependencies []string
properties = make(map[string]interface{})
requiredProperties []string
)
for i, field := range desc.GetField() {
if field.OneofIndex != nil {
continue
}
f, dep := g.fieldToSchema(field)
if f == nil {
continue
}
if limbo.IsRequiredProperty(field) {
requiredProperties = append(requiredProperties, getJSONName(field))
}
{
comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 2, i))
comment = strings.TrimSpace(comment)
if comment != "" {
f["description"] = comment
}
}
properties[getJSONName(field)] = f
if dep != "" {
dependencies = append(dependencies, dep)
}
}
schema := map[string]interface{}{
"type": "object",
"properties": properties,
}
if len(requiredProperties) > 0 {
schema["required"] = requiredProperties
}
if len(desc.OneofDecl) > 0 {
allOffDefs := make([]interface{}, 0, 1+len(desc.OneofDecl))
oneOfDefs := make([][]interface{}, len(desc.OneofDecl))
for i, field := range desc.GetField() {
if field.OneofIndex == nil {
continue
}
oneofIndex := *field.OneofIndex
f, dep := g.fieldToSchema(field)
if f == nil {
continue
}
if field.IsRepeated() {
f = map[string]interface{}{
"type": "array",
"items": f,
}
}
{
comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 2, i))
comment = strings.TrimSpace(comment)
if comment != "" {
f["description"] = comment
}
}
def := map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
getJSONName(field): f,
},
"required": []string{getJSONName(field)},
}
oneOfDefs[oneofIndex] = append(oneOfDefs[oneofIndex], def)
if dep != "" {
dependencies = append(dependencies, dep)
}
}
allOffDefs = append(allOffDefs, schema)
for i, defs := range oneOfDefs {
def := map[string]interface{}{
"oneOf": defs,
}
{
comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 8, i))
comment = strings.TrimSpace(comment)
//.........这里部分代码省略.........