tools: Move external packages constant to top level

This commit is contained in:
Marek Siarkowicz 2022-01-28 16:12:00 +01:00
parent 3df14fc24f
commit 0c67c5ca49

View File

@ -27,6 +27,11 @@ import (
"google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/reflect/protoregistry"
) )
var (
// externalPackages that are not expected to have etcd version annotation.
externalPackages = []string{"io.prometheus.client", "grpc.binarylog.v1", "google.protobuf", "google.rpc", "google.api"}
)
// printEtcdVersion writes etcd_version proto annotation to stdout and returns any errors encountered when reading annotation. // printEtcdVersion writes etcd_version proto annotation to stdout and returns any errors encountered when reading annotation.
func printEtcdVersion() []error { func printEtcdVersion() []error {
var errs []error var errs []error
@ -59,11 +64,12 @@ func printEtcdVersion() []error {
func allEtcdVersionAnnotations() (annotations []etcdVersionAnnotation, err error) { func allEtcdVersionAnnotations() (annotations []etcdVersionAnnotation, err error) {
var fileAnnotations []etcdVersionAnnotation var fileAnnotations []etcdVersionAnnotation
protoregistry.GlobalFiles.RangeFiles(func(file protoreflect.FileDescriptor) bool { protoregistry.GlobalFiles.RangeFiles(func(file protoreflect.FileDescriptor) bool {
switch string(file.Package()) { pkg := string(file.Package())
// Skip external packages that are not expected to have etcd version annotation. for _, externalPkg := range externalPackages {
case "io.prometheus.client", "grpc.binarylog.v1", "google.protobuf", "google.rpc", "google.api": if pkg == externalPkg {
return true return true
} }
}
fileAnnotations, err = fileEtcdVersionAnnotations(file) fileAnnotations, err = fileEtcdVersionAnnotations(file)
if err != nil { if err != nil {
return false return false