From 228ba7a816cd0d31ce9642ef0e6d6e78788c2d0b Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Tue, 26 Feb 2019 13:42:37 +0100 Subject: [PATCH] templates/goshared: Support nullable GoGo types --- templates/goshared/register.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/templates/goshared/register.go b/templates/goshared/register.go index 02fea53c7..be2c1e960 100644 --- a/templates/goshared/register.go +++ b/templates/goshared/register.go @@ -91,11 +91,22 @@ func (fns goSharedFuncs) accessor(ctx shared.RuleContext) string { if ctx.AccessorOverride != "" { return ctx.AccessorOverride } - name := fns.Name(ctx.Field) + + name := fns.Name(ctx.Field).String() + if name != "" && ctx.Gogo.Nullable { + return fmt.Sprintf("m.Get%s()", name) + } + if name == "" { - return fmt.Sprintf("m.%s", fns.Type(ctx.Field).Value()) + name = fmt.Sprintf("m.%s", fns.Type(ctx.Field).Value()) + } else { + name = fmt.Sprintf("m.%s", name) + } + + if !ctx.Gogo.Nullable && !ctx.Field.Type().IsRepeated() && !ctx.Field.Type().IsMap() { + return fmt.Sprintf("&%s", name) } - return fmt.Sprintf("m.Get%s()", name) + return name } func (fns goSharedFuncs) errName(m pgs.Message) pgs.Name {