plugin

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package plugin provides the core generation logic for protoc-gen-go-meta.

This package implements a Protocol Buffers compiler plugin that generates Go constants containing RPC method descriptions extracted from proto service definitions. The generated constants can be used for documentation, MCP SDK integration, or runtime introspection.

Architecture

The generation process follows this flow:

  1. Generate() iterates over all proto files marked for generation
  2. For each file, Generator.generateMetaFile() creates the output file
  3. For each service and method, RPCMetaGenerator generates description constants

Generated Output

For each RPC method, the plugin generates a constant following this pattern:

const (
    // ServiceName_MethodName_FullMethodDescription returns the description of the method.
    ServiceName_MethodName_FullMethodDescription = "Method description from proto comments"
)

Usage

This package is typically invoked through the protoc compiler:

protoc --go-meta_out=. --go-meta_opt=paths=source_relative your.proto

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(plugin *protogen.Plugin, version string) error

Generate is the main entry point for the protoc-gen-go-meta plugin. It processes all proto files in the plugin request and generates corresponding _grpc.meta.pb.go files containing RPC method description constants.

This function is called by the protoc compiler through the plugin framework. It iterates over all files marked for generation and delegates the actual code generation to the Generator type.

Parameters:

  • plugin: The protogen.Plugin instance containing the code generation request. This includes all proto files, their descriptors, and generation options.
  • version: The plugin version string to include in generated file headers. This helps track which version of the plugin generated a particular file.

Returns:

  • error: Returns nil on success, or an error if generation fails for any file. When an error occurs, it is also reported to the plugin for proper error handling.

Behavior:

  • If plugin is nil, returns nil (no-op for safety)
  • Skips files that are nil or not marked for generation
  • Stops processing on first error and reports it to the plugin

Example usage (typically called from main.go):

options.Run(func(p *protogen.Plugin) error {
    return plugin.Generate(p, version)
})

Types

type Generator

type Generator struct {
	// Version is the plugin version string included in generated file headers.
	// This helps track which version of the plugin generated a particular file,
	// useful for debugging and ensuring consistency across a codebase.
	Version string
}

Generator is the main code generator that coordinates file-level generation. It holds configuration that applies to all generated files, such as the plugin version.

The Generator is stateless with respect to individual files - each file is processed independently using the same configuration.

type RPCMetaGenerator

type RPCMetaGenerator struct {
	// contains filtered or unexported fields
}

RPCMetaGenerator generates metadata constants for a single RPC method. It extracts information from the method's proto definition (name, comments) and generates corresponding Go constants.

Each instance of RPCMetaGenerator is responsible for generating metadata for exactly one RPC method. A new instance should be created for each method.

Fields:

  • gr: Reference to the parent Generator for shared functionality
  • g: The output file writer for emitting generated code
  • method: The protogen.Method being processed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL