Documentation ¶
Overview ¶
Package bufgen does configuration-based generation.
It is used by the buf generate command.
Index ¶
- Constants
- func ConfigExists(ctx context.Context, readBucket storage.ReadBucket) (bool, error)
- type Config
- type ExternalConfigV1
- type ExternalConfigV1Beta1
- type ExternalConfigVersion
- type ExternalGoPackagePrefixConfigV1
- type ExternalManagedConfigV1
- type ExternalOptionsConfigV1Beta1
- type ExternalPluginConfigV1
- type ExternalPluginConfigV1Beta1
- type GenerateOption
- type Generator
- type GoPackagePrefixConfig
- type ManagedConfig
- type PluginConfig
- type Provider
- type ReadConfigOption
- type Strategy
Constants ¶
const ( // ExternalConfigFilePath is the default external configuration file path. ExternalConfigFilePath = "buf.gen.yaml" // V1Version is the string used to identify the v1 version of the generate template. V1Version = "v1" // V1Beta1Version is the string used to identify the v1beta1 version of the generate template. V1Beta1Version = "v1beta1" )
Variables ¶
This section is empty.
Functions ¶
func ConfigExists ¶ added in v0.44.0
ConfigExists checks if a generation configuration file exists.
Types ¶
type Config ¶
type Config struct { // Required PluginConfigs []*PluginConfig // Optional ManagedConfig *ManagedConfig }
Config is a configuration.
func ReadConfig ¶
func ReadConfig( ctx context.Context, provider Provider, readBucket storage.ReadBucket, options ...ReadConfigOption, ) (*Config, error)
ReadConfig reads the configuration from the OS or an override, if any.
Only use in CLI tools.
type ExternalConfigV1 ¶ added in v0.44.0
type ExternalConfigV1 struct { Version string `json:"version,omitempty" yaml:"version,omitempty"` Plugins []ExternalPluginConfigV1 `json:"plugins,omitempty" yaml:"plugins,omitempty"` Managed ExternalManagedConfigV1 `json:"managed,omitempty" yaml:"managed,omitempty"` }
ExternalConfigV1 is an external configuration.
type ExternalConfigV1Beta1 ¶
type ExternalConfigV1Beta1 struct { Version string `json:"version,omitempty" yaml:"version,omitempty"` Managed bool `json:"managed,omitempty" yaml:"managed,omitempty"` Plugins []ExternalPluginConfigV1Beta1 `json:"plugins,omitempty" yaml:"plugins,omitempty"` Options ExternalOptionsConfigV1Beta1 `json:"options,omitempty" yaml:"options,omitempty"` }
ExternalConfigV1Beta1 is an external configuration.
type ExternalConfigVersion ¶ added in v0.44.0
type ExternalConfigVersion struct {
Version string `json:"version,omitempty" yaml:"version,omitempty"`
}
ExternalConfigVersion defines the subset of all config file versions that is used to determine the configuration version.
type ExternalGoPackagePrefixConfigV1 ¶ added in v0.44.0
type ExternalGoPackagePrefixConfigV1 struct { Default string `json:"default,omitempty" yaml:"default,omitempty"` Except []string `json:"except,omitempty" yaml:"except,omitempty"` Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"` }
ExternalGoPackagePrefixConfigV1 is the external go_package prefix configuration.
func (ExternalGoPackagePrefixConfigV1) IsEmpty ¶ added in v0.44.0
func (e ExternalGoPackagePrefixConfigV1) IsEmpty() bool
IsEmpty returns true if the config is empty.
type ExternalManagedConfigV1 ¶ added in v0.44.0
type ExternalManagedConfigV1 struct { Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty"` CcEnableArenas *bool `json:"cc_enable_arenas,omitempty" yaml:"cc_enable_arenas,omitempty"` JavaMultipleFiles *bool `json:"java_multiple_files,omitempty" yaml:"java_multiple_files,omitempty"` JavaStringCheckUtf8 *bool `json:"java_string_check_utf8,omitempty" yaml:"java_string_check_utf8,omitempty"` OptimizeFor string `json:"optimize_for,omitempty" yaml:"optimize_for,omitempty"` GoPackagePrefix ExternalGoPackagePrefixConfigV1 `json:"go_package_prefix,omitempty" yaml:"go_package_prefix,omitempty"` }
ExternalManagedConfigV1 is an external Managed Mode configuration.
Only use outside of this package for testing.
func (ExternalManagedConfigV1) IsEmpty ¶ added in v0.44.0
func (e ExternalManagedConfigV1) IsEmpty() bool
IsEmpty returns true if the config is empty, excluding the 'Enabled' setting.
type ExternalOptionsConfigV1Beta1 ¶ added in v0.42.0
type ExternalOptionsConfigV1Beta1 struct { CcEnableArenas *bool `json:"cc_enable_arenas,omitempty" yaml:"cc_enable_arenas,omitempty"` JavaMultipleFiles *bool `json:"java_multiple_files,omitempty" yaml:"java_multiple_files,omitempty"` OptimizeFor string `json:"optimize_for,omitempty" yaml:"optimize_for,omitempty"` }
ExternalOptionsConfigV1Beta1 is an external options configuration.
type ExternalPluginConfigV1 ¶ added in v0.44.0
type ExternalPluginConfigV1 struct { Name string `json:"name,omitempty" yaml:"name,omitempty"` Out string `json:"out,omitempty" yaml:"out,omitempty"` Opt interface{} `json:"opt,omitempty" yaml:"opt,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"` Strategy string `json:"strategy,omitempty" yaml:"strategy,omitempty"` }
ExternalPluginConfigV1 is an external plugin configuration.
type ExternalPluginConfigV1Beta1 ¶
type ExternalPluginConfigV1Beta1 struct { Name string `json:"name,omitempty" yaml:"name,omitempty"` Out string `json:"out,omitempty" yaml:"out,omitempty"` Opt interface{} `json:"opt,omitempty" yaml:"opt,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"` Strategy string `json:"strategy,omitempty" yaml:"strategy,omitempty"` }
ExternalPluginConfigV1Beta1 is an external plugin configuration.
type GenerateOption ¶
type GenerateOption func(*generateOptions)
GenerateOption is an option for Generate.
func GenerateWithBaseOutDirPath ¶
func GenerateWithBaseOutDirPath(baseOutDirPath string) GenerateOption
GenerateWithBaseOutDirPath returns a new GenerateOption that uses the given base directory as the output directory.
The default is to use the current directory.
func GenerateWithIncludeImports ¶ added in v0.50.0
func GenerateWithIncludeImports() GenerateOption
GenerateWithIncludeImports says to also generate imports.
Note that this does NOT result in the Well-Known Types being generated.
type Generator ¶
type Generator interface { // Generate calls the generation logic. // // The config is assumed to be valid. If created by ReadConfig, it will // always be valid. Generate( ctx context.Context, container app.EnvStdioContainer, config *Config, image bufimage.Image, options ...GenerateOption, ) error }
Generator generates Protobuf stubs based on configurations.
type GoPackagePrefixConfig ¶ added in v0.44.0
type GoPackagePrefixConfig struct { Default string Except []bufmodule.ModuleIdentity // bufmodule.ModuleIdentity -> go_package prefix. Override map[bufmodule.ModuleIdentity]string }
GoPackagePrefixConfig is the go_package prefix configuration.
type ManagedConfig ¶ added in v0.44.0
type ManagedConfig struct { CcEnableArenas *bool JavaMultipleFiles *bool JavaStringCheckUtf8 *bool OptimizeFor *descriptorpb.FileOptions_OptimizeMode GoPackagePrefixConfig *GoPackagePrefixConfig }
ManagedConfig is the Managed Mode configuration.
type PluginConfig ¶
type PluginConfig struct { // Required Name string // Required Out string // Optional Opt string // Optional Path string // Required Strategy Strategy }
PluginConfig is a plugin configuration.
type Provider ¶ added in v0.44.0
type Provider interface { // GetConfig gets the Config for the YAML data at ExternalConfigFilePath. // // If the data is of length 0, returns the default config. GetConfig(ctx context.Context, readBucket storage.ReadBucket) (*Config, error) }
Provider is a provider.
func NewProvider ¶ added in v0.44.0
NewProvider returns a new Provider.
type ReadConfigOption ¶ added in v0.44.0
type ReadConfigOption func(*readConfigOptions)
ReadConfigOption is an option for ReadConfig.
func ReadConfigWithOverride ¶ added in v0.44.0
func ReadConfigWithOverride(override string) ReadConfigOption
ReadConfigWithOverride sets the override.
If override is set, this will first check if the override ends in .json or .yaml, if so, this reads the file at this path and uses it. Otherwise, this assumes this is configuration data in either JSON or YAML format, and unmarshals it.
If no override is set, this reads ExternalConfigFilePath in the bucket.
type Strategy ¶ added in v0.33.0
type Strategy int
Strategy is a generation stategy.
func ParseStrategy ¶ added in v0.33.0
ParseStrategy parses the Strategy.
If the empty string is provided, this is interpreted as StrategyDirectory.