Documentation ¶
Overview ¶
Package str provides string manipulation utilities.
Index ¶
- Variables
- func ExpandScanner(err error) error
- func FindVendor(path string) (index int, ok bool)
- func FoldDup(list []string) (string, string)
- func Get(ctx context.Context, url string) ([]byte, error)
- func GetMaybeInsecure(ctx context.Context, importPath string, insecure bool) (urlStr string, body io.ReadCloser, err error)
- func HasFilePathPrefix(s, prefix string) bool
- func NewWriteLimitedFilesystem(fs billy.Filesystem, max uint64) billy.Filesystem
- func SafeArg(name string) bool
- func StringList(args ...interface{}) []string
- func ToFold(s string) string
- func WithCancel(ctx context.Context, f func()) bool
- type Getter
- func (g *Getter) ClearPackageCachePartial(args []string)
- func (g *Getter) Get(ctx context.Context, path string, update bool, insecure, single bool) error
- func (g *Getter) LinkerDeps(p *Package) []string
- func (g *Getter) LoadImport(ctx context.Context, path, srcDir string, parent *Package, stk *ImportStack, ...) *Package
- func (g *Getter) VendoredImportPath(parent *Package, path string) (found string)
- type HTTPError
- type ImportMismatchError
- type ImportStack
- type NoGoError
- type Package
- type PackageError
- type PackageInternal
- type PackagePublic
- type WriteLimitedFile
- type WriteLimitedFilesystem
- func (w *WriteLimitedFilesystem) Chroot(path string) (billy.Filesystem, error)
- func (w *WriteLimitedFilesystem) Create(filename string) (billy.File, error)
- func (w *WriteLimitedFilesystem) Open(filename string) (billy.File, error)
- func (w *WriteLimitedFilesystem) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)
- func (w *WriteLimitedFilesystem) TempFile(dir, prefix string) (billy.File, error)
Constants ¶
This section is empty.
Variables ¶
var OutOfSpace = errors.New("out of space")
Functions ¶
func ExpandScanner ¶
ExpandScanner expands a scanner.List error into all the errors in the list. The default Error method only shows the first error and does not shorten paths.
func FindVendor ¶
FindVendor looks for the last non-terminating "vendor" path element in the given import path. If there isn't one, FindVendor returns ok=false. Otherwise, FindVendor returns ok=true and the index of the "vendor".
Note that terminating "vendor" elements don't count: "x/vendor" is its own package, not the vendored copy of an import "" (the empty import path). This will allow people to have packages or commands named vendor. This may help reduce breakage, or it may just be confusing. We'll see.
func FoldDup ¶
FoldDup reports a pair of strings from the list that are equal according to strings.EqualFold. It returns "", "" if there are no such strings.
func GetMaybeInsecure ¶
func GetMaybeInsecure(ctx context.Context, importPath string, insecure bool) (urlStr string, body io.ReadCloser, err error)
GetMaybeInsecure returns the body of either the importPath's https resource or, if unavailable and permitted by the security mode, the http resource.
func HasFilePathPrefix ¶
HasFilePathPrefix reports whether the filesystem path s begins with the elements in prefix.
func NewWriteLimitedFilesystem ¶
func NewWriteLimitedFilesystem(fs billy.Filesystem, max uint64) billy.Filesystem
func SafeArg ¶
SafeArg reports whether arg is a "safe" command-line argument, meaning that when it appears in a command-line, it probably doesn't have some special meaning other than its own name. Obviously args beginning with - are not safe (they look like flags). Less obviously, args beginning with @ are not safe (they look like GNU binutils flagfile specifiers, sometimes called "response files"). To be conservative, we reject almost any arg beginning with non-alphanumeric ASCII. We accept leading . _ and / as likely in file system paths. There is a copy of this function in cmd/compile/internal/gc/noder.go.
func StringList ¶
func StringList(args ...interface{}) []string
StringList flattens its arguments into a single []string. Each argument in args must have type string or []string.
func ToFold ¶
ToFold returns a string with the property that
strings.EqualFold(s, t) iff ToFold(s) == ToFold(t)
This lets us test a large set of strings for fold-equivalent duplicates without making a quadratic number of calls to EqualFold. Note that strings.ToUpper and strings.ToLower do not have the desired property in some corner cases.
func WithCancel ¶
WithCancel executes the provided function, but returns early with true if the context cancellation signal was recieved.
Types ¶
type Getter ¶
type Getter struct { Callback func(path string, files map[string]string, standard bool) error // contains filtered or unexported fields }
func (*Getter) ClearPackageCachePartial ¶
func (*Getter) LinkerDeps ¶
LinkerDeps returns the list of linker-induced dependencies for main package p.
func (*Getter) LoadImport ¶
func (g *Getter) LoadImport(ctx context.Context, path, srcDir string, parent *Package, stk *ImportStack, useVendor bool) *Package
LoadImport scans the directory named by path, which must be an import path, but possibly a local import path (an absolute file system path or one beginning with ./ or ../). A local relative path is interpreted relative to srcDir. It returns a *Package describing the package found in that directory.
func (*Getter) VendoredImportPath ¶
VendoredImportPath returns the expansion of path when it appears in parent. If parent is x/y/z, then path might expand to x/y/z/vendor/path, x/y/vendor/path, x/vendor/path, vendor/path, or else stay path if none of those exist. VendoredImportPath returns the expanded path or, if no expansion is found, the original.
type ImportMismatchError ¶
type ImportMismatchError struct {
// contains filtered or unexported fields
}
A ImportMismatchError is returned where metaImport/s are present but none match our import path.
func (ImportMismatchError) Error ¶
func (m ImportMismatchError) Error() string
type ImportStack ¶
type ImportStack []string
An ImportStack is a stack of import paths.
func (*ImportStack) Copy ¶
func (s *ImportStack) Copy() []string
func (*ImportStack) Pop ¶
func (s *ImportStack) Pop()
func (*ImportStack) Push ¶
func (s *ImportStack) Push(p string)
type Package ¶
type Package struct { PackagePublic // visible in 'go list' Internal PackageInternal // for use inside go command only }
A Package describes a single package found in a directory.
func (*Package) AllFiles ¶
AllFiles returns the names of all the files considered for the package. This is used for sanity and security checks, so we include all files, even IgnoredGoFiles, because some subcommands consider them. The go/build package filtered others out (like foo_wrongGOARCH.s) and that's OK.
type PackageError ¶
type PackageError struct { ImportStack []string // shortest path from package named on command line to this one Pos string // position of error Err string // the error itself IsImportCycle bool `json:"-"` // the error is an import cycle Hard bool `json:"-"` // whether the error is soft or hard; soft errors are ignored in some places }
A PackageError describes an error loading information about a package.
func (*PackageError) Error ¶
func (p *PackageError) Error() string
type PackageInternal ¶
type PackageInternal struct { // Unexported fields are not part of the public API. Build *build.Package Imports []*Package // this package's direct imports Local bool // imported via local path (./ or ../) Asmflags []string // -asmflags for this package Gcflags []string // -gcflags for this package Ldflags []string // -ldflags for this package Gccgoflags []string // -gccgoflags for this package }
type PackagePublic ¶
type PackagePublic struct { // Note: These fields are part of the go command's public API. // See list.go. It is okay to add fields, but not to change or // remove existing ones. Keep in sync with list.go Dir string `json:",omitempty"` // directory containing package sources ImportPath string `json:",omitempty"` // import path of package in dir ImportComment string `json:",omitempty"` // path in import comment on package statement Name string `json:",omitempty"` // package name Doc string `json:",omitempty"` // package documentation string Goroot bool `json:",omitempty"` // is this package found in the Go root? Standard bool `json:",omitempty"` // is this package part of the standard Go library? Root string `json:",omitempty"` // Go root or Go path dir containing this package // Source files // If you add to this list you MUST add to p.AllFiles (below) too. // Otherwise file name security lists will not apply to any new additions. GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) IgnoredGoFiles []string `json:",omitempty"` // .go sources ignored due to build constraints // Dependency information Imports []string `json:",omitempty"` // import paths used by this package Deps []string `json:",omitempty"` // all (recursively) imported dependencies // Error information Incomplete bool `json:",omitempty"` // was there an error loading this package or dependencies? Error *PackageError `json:",omitempty"` // error loading this package (not dependencies) DepsErrors []*PackageError `json:",omitempty"` // errors loading dependencies // contains filtered or unexported fields }
type WriteLimitedFile ¶
type WriteLimitedFile struct { billy.File // contains filtered or unexported fields }
type WriteLimitedFilesystem ¶
type WriteLimitedFilesystem struct { billy.Filesystem // contains filtered or unexported fields }
func (*WriteLimitedFilesystem) Chroot ¶
func (w *WriteLimitedFilesystem) Chroot(path string) (billy.Filesystem, error)
func (*WriteLimitedFilesystem) Create ¶
func (w *WriteLimitedFilesystem) Create(filename string) (billy.File, error)
func (*WriteLimitedFilesystem) Open ¶
func (w *WriteLimitedFilesystem) Open(filename string) (billy.File, error)
func (*WriteLimitedFilesystem) TempFile ¶
func (w *WriteLimitedFilesystem) TempFile(dir, prefix string) (billy.File, error)