Skip to content

Commit

Permalink
add modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cjp2600 committed Apr 16, 2019
1 parent 4992cbb commit ac29c72
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 50 deletions.
46 changes: 44 additions & 2 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func (p *MongoPlugin) generateModelsStructures(message *descriptor.DescriptorPro
p.P(fieldName, ` `, `primitive.ObjectID`, idName)
p.usePrimitive = true

} else if p.IsMap(field) {

m := p.GoMapType(nil, field)
//_, keyField, keyAliasField := m.GoType, m.KeyField, m.KeyAliasField
p.P(fieldName, ` `, m.GoType)

} else if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdType(field)) || p.IsGroup(field) {
if strings.ToLower(goTyp) == "*timestamp.timestamp" {
p.P(fieldName, ` time.Time`)
Expand Down Expand Up @@ -232,7 +238,24 @@ func (p *MongoPlugin) GenerateFieldConversion(field *descriptor.FieldDescriptorP
}
goTyp, _ := p.GoType(des, field)
p.In()
if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdType(field)) || p.IsGroup(field) {
if p.IsMap(field) {

m := p.GoMapType(nil, field)
_, keyField, keyAliasField := m.GoType, m.KeyField, m.KeyAliasField
keygoTyp, _ := p.GoType(nil, keyField)
keygoTyp = strings.Replace(keygoTyp, "*", "", 1)
keygoAliasTyp, _ := p.GoType(nil, keyAliasField)
keygoAliasTyp = strings.Replace(keygoAliasTyp, "*", "", 1)
//keyCapTyp := generator.CamelCase(keygoTyp)
p.P(`tt`, fieldName, ` := make(`, m.GoType, `)`)
p.P(`for k, v := range e.`, fieldName, ` {`)
p.In()
p.P(`tt`, fieldName, `[k] = v`)
p.Out()
p.P(`}`)
p.P(`resp.`, fieldName, ` = tt`, fieldName)

} else if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdType(field)) || p.IsGroup(field) {

if strings.ToLower(goTyp) == "*timestamp.timestamp" {
p.P(`ptap`, fieldName, `, _ := ptypes.TimestampProto(e.`, fieldName, `)`)
Expand Down Expand Up @@ -287,7 +310,26 @@ func (p *MongoPlugin) ToMongoGenerateFieldConversion(field *descriptor.FieldDesc
}
goTyp, _ := p.GoType(des, field)
p.In()
if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdType(field)) || p.IsGroup(field) {

if p.IsMap(field) {

m := p.GoMapType(nil, field)
_, keyField, keyAliasField := m.GoType, m.KeyField, m.KeyAliasField
keygoTyp, _ := p.GoType(nil, keyField)
keygoTyp = strings.Replace(keygoTyp, "*", "", 1)
keygoAliasTyp, _ := p.GoType(nil, keyAliasField)
keygoAliasTyp = strings.Replace(keygoAliasTyp, "*", "", 1)
//keyCapTyp := generator.CamelCase(keygoTyp)
p.P(`tt`, fieldName, ` := make(`, m.GoType, `)`)

p.P(`for k, v := range e.`, fieldName, ` {`)
p.In()
p.P(`tt`, fieldName, `[k] = v`)
p.Out()
p.P(`}`)
p.P(`resp.`, fieldName, ` = tt`, fieldName)

} else if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdType(field)) || p.IsGroup(field) {

if strings.ToLower(goTyp) == "*timestamp.timestamp" {
p.useTime = true
Expand Down
11 changes: 11 additions & 0 deletions test.pb.bom.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 60 additions & 48 deletions test.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ message User {
Token token = 12;
google.protobuf.Timestamp createdAt = 13;
google.protobuf.Timestamp updatedAt = 14;
map<string, string> arguments = 15; // аргументы условия контракта
}

message Token {
Expand Down

0 comments on commit ac29c72

Please sign in to comment.