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


Golang FieldDescriptorProto.GetDefaultValue方法代码示例

本文整理汇总了Golang中github.com/gogo/protobuf/protoc-gen-gogo/descriptor.FieldDescriptorProto.GetDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:Golang FieldDescriptorProto.GetDefaultValue方法的具体用法?Golang FieldDescriptorProto.GetDefaultValue怎么用?Golang FieldDescriptorProto.GetDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gogo/protobuf/protoc-gen-gogo/descriptor.FieldDescriptorProto的用法示例。


在下文中一共展示了FieldDescriptorProto.GetDefaultValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BuildField

func BuildField(fileDescriptorSet *descriptor.FileDescriptorSet, msg *descriptor.DescriptorProto, f *descriptor.FieldDescriptorProto, help string, proto3 bool) string {
	tooltip := ""
	colon := ":"
	if len(help) > 0 {
		tooltip = ` <a href="#" data-toggle="tooltip" title="` + strings.Replace(help, "\n", " ", -1) + `"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>`
		colon = ""
	}
	fieldname := f.GetName()
	if f.IsMessage() {
		typName := typ(fieldname, f.IsRepeated(), getMessage(f, fileDescriptorSet))
		if !f.IsRepeated() {
			return `s += '<div class="children" type="` + typName + `">' + build` + typName + `(json["` + f.GetName() + `"]);
			s += '</div>';
		s += setLink(json, "` + typName + `", "` + fieldname + `", "` + help + `");
		`
		} else {
			return `s += '<div class="children" type="` + typName + `">';
			var ` + fieldname + ` = getList(json, "` + fieldname + `");
			for (var i = 0; i < ` + fieldname + `.length; i++) {
				s += build` + typName + `(` + fieldname + `[i]);
			}
			s += '</div>';
			s += '<a href="#" class="add-child btn btn-success btn-sm" role="button" type="` + typName + `">add ` + fieldname + `</a>` + tooltip + `';
			s += '<div class="field form-group"></div>';
			`
		}
	} else {
		if !f.IsRepeated() {
			if isBool(f) {
				defaultBool := "\"nothing\""
				if proto3 {
					defaultBool = "false"
				}
				if f.DefaultValue != nil {
					defaultBool = f.GetDefaultValue()
				}
				s := `s += '<div class="field form-group"><label class="col-sm-2 control-label">` + fieldname + tooltip + colon + ` </label>';
					`
				s += `s += '<div class="col-sm-10"><div class="btn-group" data-toggle="buttons">';
					`
				s += `s += 	'<label class="btn btn-primary ' + activeradio(` + defaultBool + `, false, json["` + fieldname + `"]) + '"><input type="radio" name="` + fieldname + `" value="false" ' + radioed(` + defaultBool + `, false, json["` + fieldname + `"]) + '/>No</label>';
					`
				s += `s += 	'<label class="btn btn-primary ' + activeradio(` + defaultBool + `, true, json["` + fieldname + `"]) + '"><input type="radio" name="` + fieldname + `" value="true" ' + radioed(` + defaultBool + `, true, json["` + fieldname + `"]) + '/>Yes</label>';
					`
				s += `s += '</div></div></div>';
					`
				return s
			} else if isEnum(f) {
				enum := getEnum(fileDescriptorSet, f)
				defaultEnum := "\"nothing\""
				if proto3 {
					defaultEnum = "0"
				}
				if f.DefaultValue != nil {
					for _, v := range enum.GetValue() {
						if v.GetName() == f.GetDefaultValue() {
							defaultEnum = strconv.Itoa(int(v.GetNumber()))
							break
						}
					}
				}
				if len(enum.GetValue()) <= 4 {
					s := `s += '<div class="field form-group"><label class="col-sm-2 control-label">` + fieldname + tooltip + colon + ` </label>';
					`
					s += `s += '<div class="col-sm-10"><div class="btn-group" data-toggle="buttons">';
					`
					for _, v := range enum.GetValue() {
						num := strconv.Itoa(int(v.GetNumber()))
						s += `s += 	'<label class="btn btn-primary ' + activeradio(` + defaultEnum + `, ` + num + `, json["` + fieldname + `"]) + '"><input type="radio" name="` + fieldname + `" value="` + num + `" ' + radioed(` + defaultEnum + `, ` + num + `, json["` + fieldname + `"]) + '/> ` + v.GetName() + `</label>';
						`
					}
					s += `s += '</div></div></div>';
					`
					return s
				} else {
					s := `s += '<div class="field form-group"><label class="col-sm-2 control-label">` + fieldname + tooltip + colon + ` </label><div class="col-sm-10">';
					s += '<select class="form-control" name="` + fieldname + `">';
					`
					for _, v := range enum.GetValue() {
						num := strconv.Itoa(int(v.GetNumber()))
						s += `s += 	'<option value="` + num + `" ' + selected(` + defaultEnum + `, ` + num + `, json["` + fieldname + `"]) + '>` + v.GetName() + `</option>';
						`
					}
					s += `s += '</select></div></div>';
					`
					return s
				}
			} else if isNumber(f) {
				def := "\"\""
				if proto3 {
					def = "0"
				}
				if f.DefaultValue != nil {
					def = f.GetDefaultValue()
				}
				return `s += '<div class="field form-group"><label class="col-sm-2 control-label">` + fieldname + tooltip + colon + ` </label><div class="col-sm-10"><input class="form-control" name="` + f.GetName() + `" type="number" step="1" '+setValue(` + def + `, json["` + f.GetName() + `"])+'/></div></div>';
				`
			} else if isFloat(f) {
				def := "\"\""
				if proto3 {
//.........这里部分代码省略.........
开发者ID:gpaul,项目名称:letmegrpc,代码行数:101,代码来源:form.go


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