Skip to content

Commit

Permalink
add default pg tag
Browse files Browse the repository at this point in the history
  • Loading branch information
wxue committed Nov 14, 2019
1 parent 7d63421 commit bd6287e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,7 @@ func (g *Generator) generateMessage(message *Descriptor) {

typename, wiretype := g.GoType(message, field)
jsonName := *field.Name
// json tag
jsonTag := jsonName + ",omitempty"
repeatedNativeType := (!field.IsMessage() && !gogoproto.IsCustomType(field) && field.IsRepeated())
if !gogoproto.IsNullable(field) && !repeatedNativeType {
Expand All @@ -2842,12 +2843,23 @@ func (g *Generator) generateMessage(message *Descriptor) {
if gogoJsonTag != nil {
jsonTag = *gogoJsonTag
}
// pg tag
pgTag := jsonName
repeatedNativeType := (!field.IsMessage() && !gogoproto.IsCustomType(field) && field.IsRepeated())
if !gogoproto.IsNullable(field) && !repeatedNativeType {
pgTag = jsonName
}
gogoJsonTag := gogoproto.GetJsonTag(field)
if gogoJsonTag != nil {
pgTag = *gogoJsonTag
}
// more tags
gogoMoreTags := gogoproto.GetMoreTags(field)
moreTags := ""
if gogoMoreTags != nil {
moreTags = " " + *gogoMoreTags
}
tag := fmt.Sprintf("protobuf:%s json:%q%s", g.goTag(message, field, wiretype), jsonTag, moreTags)
tag := fmt.Sprintf("protobuf:%s json:%q pg:%q%s", g.goTag(message, field, wiretype), jsonTag, pgTag, moreTags)
if *field.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE && gogoproto.IsEmbed(field) {
fieldName = ""
}
Expand Down

0 comments on commit bd6287e

Please sign in to comment.