Skip to content

[tools] Use proto facades to make protobuf publicly available - #1165

Merged
manugarg merged 7 commits into
mainfrom
protofacade
Oct 30, 2025
Merged

manugarg merged 7 commits into
mainfrom
protofacade

Conversation

@manugarg

@manugarg manugarg commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor
  • Add a tool to generate protobuf facades (tools/genprotofacade.go) so that we can export proto types without moving protos away from the code that works with them.
  • Context: I prefer to keep protos closer to the code that implements them, e.g. following directory structure:
    internal/validators/http/{protos/config.proto, http.go}. This makes it hard (and impossible if packages are under "internal") for external package users to find all the protos. Creating a facade that exports proto types at a consolidated place, should improve the experience.

For example with the following generated package: https://github.com/cloudprober/cloudprober/blob/cff6a5fe78e9317eabe102abf992ffbd0d81d43a/pkg/protos/validators/validators.go

One could use it like this:

package mycloudprober

import (
	vpb "github.com/cloudprober/cloudprober/pkg/protos/validators"
	"google.golang.org/protobuf/proto"
)

func NewValidator() []*vpb.Validator {
	return []*vpb.Validator{
		{
			Name: "test-v1",
			Type: &vpb.Validator_HttpValidator{
				HttpValidator: &vpb.HttpValidator{
					SuccessStatusCodes: proto.String("200-299"),
				},
			},
		},
		{
			Name: "test-v2",
			Type: &vpb.Validator_IntegrityValidator{
				IntegrityValidator: &vpb.IntegrityValidator{
					Pattern: &vpb.IntegrityValidator_PatternString{
						PatternString: "test",
					},
				},
			},
		},
	}
}

@manugarg

Copy link
Copy Markdown
Contributor Author

Note: enum support is missing in this version. Validators don't have any enum so this is fine for now, but I'll follow up with enum support.

@manugarg
manugarg merged commit 5f5b0bd into main Oct 30, 2025
@manugarg
manugarg deleted the protofacade branch October 30, 2025 17:35
@manugarg manugarg added this to the v0.14.2 milestone Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant