cliproto

package
v0.0.0-...-2009ccb Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cliproto contains helper functionality for protoc plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(handler Handler)

Main runs the application using the OS runtime and calling os.Exit on the return value of Run.

func Run

func Run(handler Handler, env clienv.Env) int

Run runs the application, returning the exit code.

Env will be modified to have dummy values if fields are not set.

Types

type Env

type Env interface {
	// Stderr is the stderr.
	//
	// If no value was passed when the Env was created, this will return io.EOF on any call.
	Stderr() io.Writer
	// Getenv is the equivalent of os.Getenv.
	Getenv(key string) string
}

Env is an execution environment for the plugin.

This is a partial of clienv.Env.

type Handler

type Handler interface {
	// Handle handles the request.
	//
	// Only system errors should be returned.
	Handle(
		env Env,
		responseWriter ResponseWriter,
		request *plugin_go.CodeGeneratorRequest,
	)
}

Handler handles protoc plugin functionality.

type HandlerFunc

type HandlerFunc func(
	Env,
	ResponseWriter,
	*plugin_go.CodeGeneratorRequest,
)

HandlerFunc is a function that implements Handler.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(
	env Env,
	responseWriter ResponseWriter,
	request *plugin_go.CodeGeneratorRequest,
)

Handle implements Handler.

type ResponseWriter

type ResponseWriter interface {
	// WriteCodeGeneratorResponseFile adds the file to the response.
	//
	// Can be called multiple times.
	WriteCodeGeneratorResponseFile(*plugin_go.CodeGeneratorResponse_File)
	// WriteError writes the error to the response.
	//
	// Can be called multiple times. Errors will be concatenated by newlines.
	// Resulting error string will have spaces trimmed before creating the response.
	WriteError(string)
}

ResponseWriter is a response writer.

Not thread-safe.

Jump to

Keyboard shortcuts

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