Skip to content

Instantly share code, notes, and snippets.

@russellsimpkins
Created December 29, 2020 20:17
Show Gist options
  • Save russellsimpkins/6f2335ce6abf41eb9d980d89e003accd to your computer and use it in GitHub Desktop.
Save russellsimpkins/6f2335ce6abf41eb9d980d89e003accd to your computer and use it in GitHub Desktop.
github.com/infobloxopen/protoc-gen-gorm fix to remove warning about embedded lock
index 21c5b4a..18ad64b 100644
--- a/plugin/plugin.go
+++ b/plugin/plugin.go
@@ -662,12 +662,12 @@ func (p *OrmPlugin) generateConvertFunctions(message *generator.Descriptor) {
///// To Pb
p.P(`// ToPB runs the BeforeToPB hook if present, converts the fields of this`)
p.P(`// object to PB format, runs the AfterToPB hook, then returns the PB object`)
- p.P(`func (m *`, typeName, `ORM) ToPB (ctx context.Context) (`,
+ p.P(`func (m *`, typeName, `ORM) ToPB (ctx context.Context) (*`,
typeName, `, error) {`)
- p.P(`to := `, typeName, `{}`)
+ p.P(`to := &`, typeName, `{}`)
p.P(`var err error`)
p.P(`if prehook, ok := interface{}(m).(`, typeName, `WithBeforeToPB); ok {`)
- p.P(`if err = prehook.BeforeToPB(ctx, &to); err != nil {`)
+ p.P(`if err = prehook.BeforeToPB(ctx, to); err != nil {`)
p.P(`return to, err`)
p.P(`}`)
p.P(`}`)
@@ -680,7 +680,7 @@ func (p *OrmPlugin) generateConvertFunctions(message *generator.Descriptor) {
p.generateFieldConversion(message, field, false, ofield)
}
p.P(`if posthook, ok := interface{}(m).(`, typeName, `WithAfterToPB); ok {`)
- p.P(`err = posthook.AfterToPB(ctx, &to)`)
+ p.P(`err = posthook.AfterToPB(ctx, to)`)
p.P(`}`)
p.P(`return to, err`)
p.P(`}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment