当前位置: 首页>>代码示例>>Golang>>正文


Golang Descriptor.GetFieldDescriptor方法代码示例

本文整理汇总了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)
	}
}
开发者ID:limbo-services,项目名称:core,代码行数:59,代码来源:svcauth.go

示例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)
		}
	}
}
开发者ID:limbo-services,项目名称:core,代码行数:67,代码来源:svcauth.go


注:本文中的limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.GetFieldDescriptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。