Back to godoc.org

Package fetch

v0.20.5
Latest Go to latest
Published: Jul 24, 2020 | License: Apache-2.0 | Module: github.com/bufbuild/buf

Index

Package Files

Constants

const (
	// FileSchemeHTTP is the http file scheme.
	FileSchemeHTTP FileScheme = iota + 1
	// FileSchemeHTTPS is the https file scheme.
	FileSchemeHTTPS
	// FileSchemeLocal is the local file scheme.
	FileSchemeLocal
	// FileSchemeStdio is the stdio file scheme.
	//
	// This can reference either stdin or stdout depending on if we are
	// reading or writing.
	FileSchemeStdio
	// FileSchemeStdin is the stdin file scheme.
	FileSchemeStdin
	// FileSchemeStdout is the stdout file scheme.
	FileSchemeStdout
	// FileSchemeNull is the null file scheme.
	FileSchemeNull

	// GitSchemeHTTP is the http git scheme.
	GitSchemeHTTP GitScheme = iota + 1
	// GitSchemeHTTPS is the https git scheme.
	GitSchemeHTTPS
	// GitSchemeLocal is the local git scheme.
	GitSchemeLocal
	// GitSchemeSSH is the ssh git scheme.
	GitSchemeSSH

	// ArchiveTypeTar is a tar archive.
	ArchiveTypeTar ArchiveType = iota + 1
	// ArchiveTypeZip is a zip archive.
	ArchiveTypeZip

	// CompressionTypeNone is no compression.
	CompressionTypeNone CompressionType = iota + 1
	// CompressionTypeGzip is gzip compression.
	CompressionTypeGzip
	// CompressionTypeZstd is zstd compression.
	CompressionTypeZstd
)

type ArchiveFormatOption

type ArchiveFormatOption func(*archiveFormatInfo)

ArchiveFormatOption is a archive format option.

func WithArchiveDefaultCompressionType

func WithArchiveDefaultCompressionType(defaultCompressionType CompressionType) ArchiveFormatOption

WithArchiveDefaultCompressionType sets the default compression type.

Note this should never be set for zip.

type ArchiveRef

type ArchiveRef interface {
	FileRef
	BucketRef
	ArchiveType() ArchiveType
	StripComponents() uint32
	// contains filtered or unexported methods
}

ArchiveRef is an archive reference.

An ArchiveRef is a special type of reference that can be either a FileRef or a BucketRef. Note that if ArchiveType is ArchiveTypeZip, CompressionType will always be CompressionTypeNone.

func NewArchiveRef

func NewArchiveRef(
	path string,
	archiveType ArchiveType,
	compressionType CompressionType,
	stripComponents uint32,
) (ArchiveRef, error)

NewArchiveRef returns a new ArchiveRef.

type ArchiveType

type ArchiveType int

ArchiveType is a archive type.

type BucketRef

type BucketRef interface {
	Ref
	// contains filtered or unexported methods
}

BucketRef is a bucket reference.

type CompressionType

type CompressionType int

CompressionType is a compression type.

type DirFormatOption

type DirFormatOption func(*dirFormatInfo)

DirFormatOption is a dir format option.

type DirRef

type DirRef interface {
	BucketRef
	// contains filtered or unexported methods
}

DirRef is a local directory reference.

func NewDirRef

func NewDirRef(path string) (DirRef, error)

NewDirRef returns a new DirRef.

type FileRef

type FileRef interface {
	Ref
	FileScheme() FileScheme
	CompressionType() CompressionType
	// contains filtered or unexported methods
}

FileRef is a file reference.

type FileScheme

type FileScheme int

FileScheme is a file scheme.

type GetBucketOption

type GetBucketOption func(*getBucketOptions)

GetBucketOption is a GetBucket option

func WithGetBucketMapper

func WithGetBucketMapper(mapper storage.Mapper) GetBucketOption

WithGetBucketMapper returns a GetBucketOption that adds the Mapper.

type GetFileOption

type GetFileOption func(*getFileOptions)

GetFileOption is a GetFile option

func WithGetFileKeepFileCompression

func WithGetFileKeepFileCompression() GetFileOption

WithGetFileKeepFileCompression says to return s compressed.

type GetParsedRefOption

type GetParsedRefOption func(*getParsedRefOptions)

GetParsedRefOption is a GetParsedRef option

func WithAllowedFormats

func WithAllowedFormats(formats ...string) GetParsedRefOption

WithAllowedFormats limits the allowed formats to the given formats.

type GitFormatOption

type GitFormatOption func(*gitFormatInfo)

GitFormatOption is a git format option.

type GitRef

type GitRef interface {
	BucketRef
	GitScheme() GitScheme
	// Optional. May be nil, in which case clone the default branch.
	GitName() git.Name
	// Will always be >= 1
	Depth() uint32
	RecurseSubmodules() bool
	// contains filtered or unexported methods
}

GitRef is a git reference.

func NewGitRef

func NewGitRef(
	path string,
	gitName git.Name,
	depth uint32,
	recurseSubmodules bool,
) (GitRef, error)

NewGitRef returns a new GitRef.

type GitScheme

type GitScheme int

GitScheme is a git scheme.

type HasFormat

type HasFormat interface {
	Format() string
}

HasFormat is an object that has a format.

type ParsedArchiveRef

type ParsedArchiveRef interface {
	ArchiveRef
	HasFormat
}

ParsedArchiveRef is a parsed ArchiveRef.

type ParsedBucketRef

type ParsedBucketRef interface {
	BucketRef
	HasFormat
}

ParsedBucketRef is a parsed BucketRef.

type ParsedDirRef

type ParsedDirRef interface {
	DirRef
	HasFormat
}

ParsedDirRef is a parsed DirRef.

type ParsedFileRef

type ParsedFileRef interface {
	FileRef
	HasFormat
}

ParsedFileRef is a parsed FileRef.

type ParsedGitRef

type ParsedGitRef interface {
	GitRef
	HasFormat
}

ParsedGitRef is a parsed GitRef.

type ParsedRef

type ParsedRef interface {
	Ref
	HasFormat
}

ParsedRef is a parsed Ref.

type ParsedSingleRef

type ParsedSingleRef interface {
	SingleRef
	HasFormat
}

ParsedSingleRef is a parsed SingleRef.

type PutFileOption

type PutFileOption func(*putFileOptions)

PutFileOption is a PutFile option

func WithPutFileNoFileCompression

func WithPutFileNoFileCompression() PutFileOption

WithPutFileNoFileCompression says to put s uncompressed.

type RawRef

type RawRef struct {
	// Will always be set
	// Not normalized yet
	Path string
	// Will always be set
	// Set via RawRefProcessor if not explicitly set
	Format string
	// Only set for single, archive formats
	// Cannot be set for zip archives
	CompressionType CompressionType
	// Only set for git formats
	// Only one of GitBranch and GitTag will be set
	GitBranch string
	// Only set for git formats
	// Only one of GitBranch and GitTag will be set
	GitTag string
	// Only set for git formats
	// Specifies an exact git reference to use with git checkout.
	// Can be used on its own or with GitBranch. Not allowed with GitTag.
	// This is defined as anything that can be given to git checkout.
	GitRef string
	// Only set for git formats
	GitRecurseSubmodules bool
	// Only set for git formats.
	// The depth to use when cloning a repository. Only allowed when GitRef
	// is set. Defaults to 50 if unset.
	GitDepth uint32
	// Only set for archive formats
	ArchiveStripComponents uint32
}

RawRef is an unprocessed ref used for WithRefProcessor.

A RawRefProcessor will allow modifications to a RawRef before continuing parsing. This allows defaults to be inferred from the path.

The Path will be the only value set when the RawRefProcessor is invoked, and is not normalized. After the RawRefProcessor is called, options will be parsed.

type Reader

type Reader interface {
	// GetFile gets the file.
	// SingleRefs and ArchiveRefs will result in decompressed files unless KeepFileCompression is set.
	GetFile(
		ctx context.Context,
		container app.EnvStdinContainer,
		fileRef FileRef,
		options ...GetFileOption,
	) (io.ReadCloser, error)
	// GetBucket gets the bucket .
	GetBucket(
		ctx context.Context,
		container app.EnvStdinContainer,
		bucketRef BucketRef,
		options ...GetBucketOption,
	) (storage.ReadBucketCloser, error)
}

Reader is a reader.

func NewReader

func NewReader(
	logger *zap.Logger,
	options ...ReaderOption,
) Reader

NewReader returns a new Reader.

type ReaderOption

type ReaderOption func(*reader)

ReaderOption is an Reader option.

func WithReaderGit

func WithReaderGit(gitCloner git.Cloner) ReaderOption

WithReaderGit enables Git.

func WithReaderHTTP

func WithReaderHTTP(httpClient *http.Client, httpAuthenticator httpauth.Authenticator) ReaderOption

WithReaderHTTP enables HTTP.

func WithReaderLocal

func WithReaderLocal() ReaderOption

WithReaderLocal enables local.

func WithReaderStdio

func WithReaderStdio() ReaderOption

WithReaderStdio enables stdio.

type Ref

type Ref interface {
	// Path is the path to.
	//
	// This will be the non-empty path minus the scheme for http and https files.
	// This will be the non-empty normalized file path for local files.
	// This will be empty for stdio and null files.
	// This will be the non-empty normalized directory path for directories.
	// This will be the non-empty path minus the scheme for http, https, and ssh git repositories.
	// This will be the non-empty normalized directory path for local git repositories.
	Path() string
	// contains filtered or unexported methods
}

Ref is a reference.

type RefParser

type RefParser interface {
	// GetParsedRef gets the ParsedRef for the value.
	//
	// The returned ParsedRef will be either a ParsedSingleRef, ParsedArchiveRef, ParsedDirRef, or ParsedGitRef.
	//
	// The options should be used to validate that you are getting one of the correct formats.
	GetParsedRef(ctx context.Context, value string, options ...GetParsedRefOption) (ParsedRef, error)
}

RefParser parses references.

func NewRefParser

func NewRefParser(logger *zap.Logger, options ...RefParserOption) RefParser

NewRefParser returns a new RefParser.

type RefParserOption

type RefParserOption func(*refParser)

RefParserOption is an RefParser option.

func WithArchiveFormat

func WithArchiveFormat(format string, archiveType ArchiveType, options ...ArchiveFormatOption) RefParserOption

WithArchiveFormat attaches the given format as an archive format.

It is up to the user to not incorrectly attached a format twice.

func WithDirFormat

func WithDirFormat(format string, options ...DirFormatOption) RefParserOption

WithDirFormat attaches the given format as a dir format.

It is up to the user to not incorrectly attached a format twice.

func WithGitFormat

func WithGitFormat(format string, options ...GitFormatOption) RefParserOption

WithGitFormat attaches the given format as a git format.

It is up to the user to not incorrectly attached a format twice.

func WithRawRefProcessor

func WithRawRefProcessor(rawRefProcessor func(*RawRef) error) RefParserOption

WithRawRefProcessor attaches the given RawRefProcessor.

If format is not manually specified, the RefParser will use this format parser with the raw path, that is not normalized.

func WithSingleFormat

func WithSingleFormat(format string, options ...SingleFormatOption) RefParserOption

WithSingleFormat attaches the given format as a single format.

It is up to the user to not incorrectly attached a format twice.

type SingleFormatOption

type SingleFormatOption func(*singleFormatInfo)

SingleFormatOption is a single format option.

func WithSingleDefaultCompressionType

func WithSingleDefaultCompressionType(defaultCompressionType CompressionType) SingleFormatOption

WithSingleDefaultCompressionType sets the default compression type.

type SingleRef

type SingleRef interface {
	FileRef
	// contains filtered or unexported methods
}

SingleRef is a non-archive file reference.

func NewSingleRef

func NewSingleRef(path string, compressionType CompressionType) (SingleRef, error)

NewSingleRef returns a new SingleRef.

type Writer

type Writer interface {
	// PutFile puts the file.
	PutFile(
		ctx context.Context,
		container app.EnvStdoutContainer,
		fileRef FileRef,
		options ...PutFileOption,
	) (io.WriteCloser, error)
}

Writer is a writer.

func NewWriter

func NewWriter(
	logger *zap.Logger,
	options ...WriterOption,
) Writer

NewWriter returns a new Writer.

type WriterOption

type WriterOption func(*writer)

WriterOption is an Writer option.

func WithWriterLocal

func WithWriterLocal() WriterOption

WithWriterLocal enables local.

func WithWriterStdio

func WithWriterStdio() WriterOption

WithWriterStdio enables stdio.

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

Jump to identifier

Keyboard shortcuts

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