本文整理汇总了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 {
//.........这里部分代码省略.........