Skip to content

Commit

Permalink
The generated well known Golang code now includes a link to the used …
Browse files Browse the repository at this point in the history
…package on the registry
  • Loading branch information
maoueh committed Jan 19, 2024
1 parent 03efa9b commit dc641a3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 52 deletions.
25 changes: 22 additions & 3 deletions protoregistry/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ func main() {
if file.Name != nil {
name = *file.Name
}
protofiles = append(protofiles, ProtoFile{name, cnt})

protofiles = append(protofiles, ProtoFile{
Name: name,
Data: cnt,
BufRegistryPackageURL: buildBufRegistryPackageURL(wellKnownProtoRepo, deferPtr(file.Package, ""), fileDescriptorSet.Msg.Version),
})
}
// avoid hitting the buf.build rate limit
time.Sleep(1 * time.Second)
Expand Down Expand Up @@ -109,9 +114,15 @@ func main() {
fmt.Println("Done creating well known registry")
}

func buildBufRegistryPackageURL(module string, fullyQualifiedPackage string, revision string) string {
// Example full URL is https://buf.build/streamingfast/firehose-near/docs/146e2ae8bd9b49e29b132b8627f29a70:sf.near.type.v1
return fmt.Sprintf("https://%s/docs/%s:%s", module, revision, fullyQualifiedPackage)
}

type ProtoFile struct {
Name string
Data []byte
Name string
Data []byte
BufRegistryPackageURL string
}

func templateFunctions() template.FuncMap {
Expand All @@ -124,3 +135,11 @@ func templateFunctions() template.FuncMap {
},
}
}

func deferPtr[T any](in *T, orValue T) T {
if in == nil {
return orValue
}

return *in
}
11 changes: 6 additions & 5 deletions protoregistry/generator/template.gotmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by generate_flags, DO NOT EDIT!
// Code generated by 'go run github.com/streamingfast/firehose-core/protoregistry/generator well_known.go protoregistry', DO NOT EDIT!
package {{.Package}}

import (
Expand All @@ -15,10 +15,11 @@ var WellKnownRegistry = New()

func init() {
protoFiles := []string{
{{range .ProtoFiles}}
// {{.Name}}
"{{.Data | toHex}}",
{{end}}
{{- range .ProtoFiles}}

// {{.Name}} ({{.BufRegistryPackageURL}})
"{{.Data | toHex}}",
{{- end}}
}

var files []*descriptorpb.FileDescriptorProto
Expand Down
Loading

0 comments on commit dc641a3

Please sign in to comment.