protoc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompileResult

type CompileResult struct {
	// The failures from all calls.
	Failures []*text.Failure
	// Will not be set if there are any failures.
	FileDescriptorSets []*descriptor.FileDescriptorSet
}

CompileResult is the result of a compile

type Compiler

type Compiler interface {
	// Compile the protobuf files with protoc.
	//
	// If there are compile failures, they will be returned in the slice
	// and there will be no error. The caller can determine if this is
	// an error case. If there is any other type of error, or some output
	// from protoc cannot be interpreted, an error will be returned.
	//
	// FileDescriptorSet will only be set if the CompilerWithFileDescriptorSet
	// option is used.
	Compile(...*file.ProtoSet) (*CompileResult, error)

	// Return the protoc commands that would be run on Compile.
	//
	// This will ignore the CompilerWithFileDescriptorSet option.
	ProtocCommands(...*file.ProtoSet) ([]string, error)
}

Compiler compiles protobuf files.

func NewCompiler

func NewCompiler(options ...CompilerOption) Compiler

NewCompiler returns a new Compiler.

type CompilerOption

type CompilerOption func(*compiler)

CompilerOption is an option for a new Compiler.

func CompilerWithCachePath

func CompilerWithCachePath(cachePath string) CompilerOption

CompilerWithCachePath returns a CompilerOption that uses the given cachePath.

The default is ${XDG_CACHE_HOME}/prototool/$(uname -s)/$(uname -m).

func CompilerWithFileDescriptorSet

func CompilerWithFileDescriptorSet() CompilerOption

CompilerWithFileDescriptorSet says to also return the FileDescriptorSet.

func CompilerWithGen

func CompilerWithGen() CompilerOption

CompilerWithGen says to also generate the code.

func CompilerWithLogger

func CompilerWithLogger(logger *zap.Logger) CompilerOption

CompilerWithLogger returns a CompilerOption that uses the given logger.

The default is to use zap.NewNop().

func CompilerWithProtocURL

func CompilerWithProtocURL(protocURL string) CompilerOption

CompilerWithProtocURL returns a CompilerOption that uses the given protoc zip file URL.

The default is https://github.com/google/protobuf/releases/download/vVERSION/protoc-VERSION-OS-ARCH.zip.

type Downloader

type Downloader interface {
	// Download protobuf.
	//
	// If already downloaded, this has no effect. This is thread-safe.
	// This will download to ${XDG_CACHE_HOME}/prototool/$(uname -s)/$(uname -m)
	// unless overridden by a DownloaderOption.
	// If ${XDG_CACHE_HOME} is not set, it defaults to ${HOME}/Library/Caches on
	// Darwin, and ${HOME}/.cache on Linux.
	// If ${HOME} is not set, an error will be returned.
	//
	// Returns the path to the downloaded protobuf artifacts.
	//
	// ProtocPath and WellKnownTypesIncludePath implicitly call this.
	Download() (string, error)

	// Get the path to protoc.
	//
	// If not downloaded, this downloads and caches protobuf. This is thread-safe.
	ProtocPath() (string, error)

	// Get the path to include for the well-known types.
	//
	// Inside this directory will be the subdirectories google/protobuf.
	//
	// If not downloaded, this downloads and caches protobuf. This is thread-safe.
	WellKnownTypesIncludePath() (string, error)

	// Delete any downloaded artifacts.
	//
	// This is not thread-safe and no calls to other functions can be reliably
	// made simultaneously.
	Delete() error
}

Downloader downloads and caches protobuf.

func NewDownloader

func NewDownloader(config settings.Config, options ...DownloaderOption) Downloader

NewDownloader returns a new Downloader for the given config and DownloaderOptions.

type DownloaderOption

type DownloaderOption func(*downloader)

DownloaderOption is an option for a new Downloader.

func DownloaderWithCachePath

func DownloaderWithCachePath(cachePath string) DownloaderOption

DownloaderWithCachePath returns a DownloaderOption that uses the given cachePath.

The default is ${XDG_CACHE_HOME}/prototool/$(uname -s)/$(uname -m).

func DownloaderWithLogger

func DownloaderWithLogger(logger *zap.Logger) DownloaderOption

DownloaderWithLogger returns a DownloaderOption that uses the given logger.

The default is to use zap.NewNop().

func DownloaderWithProtocURL

func DownloaderWithProtocURL(protocURL string) DownloaderOption

DownloaderWithProtocURL returns a DownloaderOption that uses the given protoc zip file URL.

The default is https://github.com/google/protobuf/releases/download/vVERSION/protoc-VERSION-OS-ARCH.zip.

Jump to

Keyboard shortcuts

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