Back to godoc.org

Package protoc

v1.3.0
Latest Go to latest
Published: Sep 17, 2018 | License: MIT | Module: github.com/demdxx/prototool

Index

Package Files

type CompileResult

type CompileResult struct {
	// The failures from all calls.
	Failures []*text.Failure
	// Will not be set if there are any failures.
	//
	// Will only be set if the CompilerWithFileDescriptorSet
	// option is used.
	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.
	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 CompilerWithProtocBinPath

func CompilerWithProtocBinPath(protocBinPath string) CompilerOption

CompilerWithProtocBinPath returns a CompilerOption that uses the given protoc binary path.

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/protocolbuffers/protobuf/releases/download/vVERSION/protoc-VERSION-OS-ARCH.zip.

func CompilerWithProtocWKTPath

func CompilerWithProtocWKTPath(protocWKTPath string) CompilerOption

CompilerWithProtocWKTPath returns a CompilerOption that uses the given path to include the well-known types.

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, error)

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 DownloaderWithProtocBinPath

func DownloaderWithProtocBinPath(protocBinPath string) DownloaderOption

DownloaderWithProtocBinPath returns a DownloaderOption that uses the given protoc binary path.

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/protocolbuffers/protobuf/releases/download/vVERSION/protoc-VERSION-OS-ARCH.zip.

func DownloaderWithProtocWKTPath

func DownloaderWithProtocWKTPath(protocWKTPath string) DownloaderOption

DownloaderWithProtocWKTPath returns a DownloaderOption that uses the given path to include the well-known types.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier