Skip to content

Commit

Permalink
fix oneof difference (#2)
Browse files Browse the repository at this point in the history
* fix oneof difference
* accidental line
* remove ambiguity from test
  • Loading branch information
EItanya authored and soloio-bulldozer[bot] committed Jan 3, 2020
1 parent 1a24aaf commit cf0e4f9
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 81 deletions.
32 changes: 18 additions & 14 deletions templates/go/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ func register(tpl *template.Template, params pgs.Parameters) {
}

tpl.Funcs(map[string]interface{}{
"snakeCase": fns.snakeCase,
"cmt": pgs.C80,
"isBytes": fns.isBytes,
"lit": fns.lit,
"lookup": fns.lookup,
"msgTyp": fns.msgTyp,
"name": fns.Name,
"oneof": fns.oneofTypeName,
"pkg": fns.PackageName,
"typ": fns.Type,
"externalEnums": fns.externalEnums,
"enumPackages": fns.enumPackages,
"render": fns.render,
"fullPackageName": fns.fullPackageName,
"snakeCase": fns.snakeCase,
"cmt": pgs.C80,
"isBytes": fns.isBytes,
"lit": fns.lit,
"lookup": fns.lookup,
"msgTyp": fns.msgTyp,
"name": fns.Name,
"oneof": fns.oneofTypeName,
"pkg": fns.PackageName,
"typ": fns.Type,
"externalEnums": fns.externalEnums,
"enumPackages": fns.enumPackages,
"render": fns.render,
})
}

Expand All @@ -47,6 +48,10 @@ func (fns goSharedFuncs) pointerAccessor(field pgs.Field) string {
return fmt.Sprintf("&m.%s", fns.Name(field))
}

func (fns goSharedFuncs) fullPackageName(msg pgs.Message) string {
return fmt.Sprintf("%s.%s.%s", msg.Package().ProtoName(), fns.ImportPath(msg), fns.Name(msg))
}

func (fns goSharedFuncs) lookup(f pgs.Field, name string) string {
return fmt.Sprintf(
"_%s_%s_%s",
Expand Down Expand Up @@ -102,7 +107,6 @@ func (fns goSharedFuncs) oneofTypeName(f pgs.Field) pgsgo.TypeName {
return pgsgo.TypeName(fns.OneofOption(f)).Pointer()
}


func (fns goSharedFuncs) msgTyp(message pgs.Message) pgsgo.TypeName {
return pgsgo.TypeName(fns.Name(message))
}
Expand Down
6 changes: 4 additions & 2 deletions templates/go/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const msgTpl = `
func (m {{ (msgTyp .).Pointer }}) Hash(hasher hash.Hash64) (uint64, error) {
if m == nil { return 0, nil }
if hasher == nil { hasher = fnv.New64() }
{{- if not (eq (len .Fields) 0) }}
var err error
{{- end }}
if _, err = hasher.Write([]byte("{{ fullPackageName . }}")); err != nil {
return 0, err
}
{{ range .NonOneOfFields }}
{{ render . }}
{{ end }}
Expand Down
7 changes: 0 additions & 7 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,12 @@ type FilePathFn func(f pgs.File, ctx pgsgo.Context, tpl *template.Template) *pgs

func Template(params pgs.Parameters) *template.Template {
tpl := template.New("go")
// shared.RegisterFunctions(tpl, params)
golang.Register(tpl, params)
return tpl
}

func FilePathFor(tpl *template.Template, moduleName string) FilePathFn {
switch tpl.Name() {
// case "h":
// return cc.CcFilePath
// case "cc":
// return cc.CcFilePath
// case "java":
// return java.JavaFilePath
default:
return func(f pgs.File, ctx pgsgo.Context, tpl *template.Template) *pgs.FilePath {
out := ctx.OutputPath(f)
Expand Down
192 changes: 143 additions & 49 deletions tests/api/hello.pb.go

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

Loading

0 comments on commit cf0e4f9

Please sign in to comment.