Skip to content

Commit

Permalink
Merge pull request #11 from pquerna/pq/uplift_version
Browse files Browse the repository at this point in the history
Uplift Version to a numeric Dynamo field
  • Loading branch information
pquerna authored Feb 23, 2021
2 parents f42b313 + c5ce025 commit 48b714f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/pgd/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ func (m *Module) applyMarshal(f *jen.File, in pgs.File) error {
}
}

if mext.Version != nil {
refId++
vname := fmt.Sprintf("v%d", refId)
// Version() (int64, error)
stmts = append(stmts, jen.List(jen.Id(vname), jen.Id("err")).Op(":=").Id("p").Dot("Version").Call())
stmts = append(stmts,
jen.If(jen.Id("err").Op("!=").Nil()).Block(
jen.Return(jen.Id("err")),
),
)
d[jen.Lit("version")] = jen.Op("&").Qual(dynamoPkg, "AttributeValue").Values(jen.Dict{
jen.Id("N"): jen.Qual(awsPkg, "String").Call(jen.Qual(strconvPkg, "FormatInt").Call(jen.Id(vname), jen.Lit(10))),
})
}

typeName := fmt.Sprintf("type.googleapis.com/%s.%s", msg.Package().ProtoName().String(), msg.Name())

needProtoBuffer = true
Expand Down Expand Up @@ -843,4 +858,4 @@ func numberParseStatement(pt pgs.ProtoType, access *jen.Statement) *jen.Statemen
)
}
return rv
}
}

0 comments on commit 48b714f

Please sign in to comment.