本文整理汇总了Golang中limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.GetFieldDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Golang Descriptor.GetFieldDescriptor方法的具体用法?Golang Descriptor.GetFieldDescriptor怎么用?Golang Descriptor.GetFieldDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor
的用法示例。
在下文中一共展示了Descriptor.GetFieldDescriptor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setMessage
func (g *svcauth) setMessage(inputType *generator.Descriptor, path, input, output string, inputIsNullable bool) {
var (
goPath string
outputIsNullable bool
)
goPath = input
if inputIsNullable {
g.P(`if `, goPath, `== nil {`)
g.P(goPath, `= &`, g.gen.TypeName(inputType), `{}`)
g.P(`}`)
}
for path != "" {
// split path
part := path
idx := strings.IndexByte(path, '.')
if idx >= 0 {
part = path[:idx]
path = path[idx+1:]
} else {
path = ""
}
// Get Field
field := inputType.GetFieldDescriptor(part)
if field == nil {
g.gen.Fail("unknown field", part, "in message", inputType.GetName())
}
if !field.IsMessage() {
g.gen.Fail("expected a message")
}
// Append code
fieldGoName := g.gen.GetFieldName(inputType, field)
goPath += "." + fieldGoName
inputType = g.messages[strings.TrimPrefix(field.GetTypeName(), ".")]
if gogoproto.IsNullable(field) && path != "" {
g.P(`if `, goPath, `== nil {`)
g.P(goPath, `= &`, g.gen.TypeName(inputType), `{}`)
g.P(`}`)
}
if gogoproto.IsNullable(field) {
outputIsNullable = true
} else {
outputIsNullable = false
}
}
if outputIsNullable {
g.P(goPath, ` = `, output)
} else {
g.P(goPath, ` = &`, output)
}
}
示例2: getMessage
func (g *svcauth) getMessage(inputType *generator.Descriptor, path, input, output string, inputIsNullable bool) {
var (
checks []string
goPath string
isNullable = inputIsNullable
)
if path == "." {
g.P(output, ` = `, input)
return
}
goPath = input
if inputIsNullable {
checks = append(checks, input+" != nil")
}
for path != "" {
// split path
part := path
idx := strings.IndexByte(path, '.')
if idx >= 0 {
part = path[:idx]
path = path[idx+1:]
} else {
path = ""
}
// Get Field
field := inputType.GetFieldDescriptor(part)
if field == nil {
g.gen.Fail("unknown field", strconv.Quote(part), "in message", inputType.GetName())
}
if !field.IsMessage() {
g.gen.Fail("expected a message")
}
// Append code
fieldGoName := g.gen.GetFieldName(inputType, field)
goPath += "." + fieldGoName
if gogoproto.IsNullable(field) {
checks = append(checks, goPath+" != nil")
isNullable = true
} else {
isNullable = false
}
inputType = g.messages[strings.TrimPrefix(field.GetTypeName(), ".")]
}
if len(checks) > 0 {
g.P(`if `, strings.Join(checks, " && "), `{`)
if isNullable {
g.P(output, ` = `, goPath)
} else {
g.P(output, ` = &`, goPath)
}
g.P(`}`)
} else {
if isNullable {
g.P(output, ` = `, goPath)
} else {
g.P(output, ` = &`, goPath)
}
}
}