buf: github.com/bufbuild/buf/internal/pkg/app/appproto Index | Files | Directories

package appproto

import "github.com/bufbuild/buf/internal/pkg/app/appproto"

Package appproto contains helper functionality for protoc plugins.

Note this is currently implicitly tested through buf's protoc command. If this were split out into a separate package, testing would need to be moved to this package.

Index

Package Files

appproto.go generator.go response_writer.go util.go

func NewRunFunc Uses

func NewRunFunc(handler Handler) func(context.Context, app.Container) error

NewRunFunc returns a new RunFunc for app.Main and app.Run.

type GenerateOption Uses

type GenerateOption func(*generateOptions)

GenerateOption is an option for Generate.

func GenerateWithInsertionPointReadBucket Uses

func GenerateWithInsertionPointReadBucket(
    insertionPointReadBucket storage.ReadBucket,
) GenerateOption

GenerateWithInsertionPointReadBucket returns a new GenerateOption that uses the given ReadBucket to read from for insertion points.

If this is not specified, insertion points are not supported.

type Generator Uses

type Generator interface {
    // Generate generates to the bucket.
    Generate(
        ctx context.Context,
        container app.EnvStderrContainer,
        writeBucket storage.WriteBucket,
        requests []*pluginpb.CodeGeneratorRequest,
        options ...GenerateOption,
    ) error
}

Generator executes the Handler using protoc's plugin execution logic.

This invokes a Handler and writes out the response to the output location, additionally accounting for insertion point logic.

If multiple requests are specified, these are executed in parallel and the result is combined into one response that is written.

func NewGenerator Uses

func NewGenerator(
    logger *zap.Logger,
    handler Handler,
) Generator

NewGenerator returns a new Generator.

type Handler Uses

type Handler interface {
    // Handle handles the plugin.
    //
    // This function can assume the request is valid.
    Handle(
        ctx context.Context,
        container app.EnvStderrContainer,
        responseWriter ResponseWriter,
        request *pluginpb.CodeGeneratorRequest,
    ) error
}

Handler is a protoc plugin handler

type HandlerFunc Uses

type HandlerFunc func(
    context.Context,
    app.EnvStderrContainer,
    ResponseWriter,
    *pluginpb.CodeGeneratorRequest,
) error

HandlerFunc is a handler function.

func (HandlerFunc) Handle Uses

func (h HandlerFunc) Handle(
    ctx context.Context,
    container app.EnvStderrContainer,
    responseWriter ResponseWriter,
    request *pluginpb.CodeGeneratorRequest,
) error

Handle implements Handler.

type ResponseWriter Uses

type ResponseWriter interface {
    // Add adds the file to the response.
    //
    // Returns error if nil, the name is empty, or the name is already added.
    Add(*pluginpb.CodeGeneratorResponse_File) error
    // AddError adds the error message to the response.
    //
    // If there is an existing error message, this will be concatenated with a newline.
    AddError(message string) error
    // SetFeatureProto3Optional sets the proto3 optional feature.
    SetFeatureProto3Optional()
}

ResponseWriter handles CodeGeneratorResponses.

Directories

PathSynopsis
appprotoexecPackage appprotoexec provides appproto.Handlers for binary plugins.

Package appproto imports 19 packages (graph) and is imported by 1 packages. Updated 2020-10-20. Refresh now. Tools for package owners.