Skip to content

Commit

Permalink
templates/goshared: Support nullable GoGo types
Browse files Browse the repository at this point in the history
  • Loading branch information
rvolosatovs committed Feb 26, 2019
1 parent f5dfc51 commit 6fdecd4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions templates/goshared/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return fmt.Sprintf("&%s", name)
}
return fmt.Sprintf("m.Get%s()", name)
return name
}

func (fns goSharedFuncs) errName(m pgs.Message) pgs.Name {
Expand Down

0 comments on commit 6fdecd4

Please sign in to comment.