github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/search/search.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package search
     6  
     7  // A Match represents the result of matching a single package pattern.
     8  type Match struct {
     9  	pattern string
    10  	Dirs    []string
    11  	Pkgs    []string
    12  	Errs    []error
    13  }
    14  
    15  // NewMatch returns a Match describing the given pattern,
    16  // without resolving its packages or errors.
    17  func NewMatch(pattern string) *Match
    18  
    19  // Pattern returns the pattern to be matched.
    20  func (m *Match) Pattern() string
    21  
    22  // AddError appends a MatchError wrapping err to m.Errs.
    23  func (m *Match) AddError(err error)
    24  
    25  // IsLiteral reports whether the pattern is free of wildcards and meta-patterns.
    26  //
    27  // A literal pattern must match at most one package.
    28  func (m *Match) IsLiteral() bool
    29  
    30  // IsLocal reports whether the pattern must be resolved from a specific root or
    31  // directory, such as a filesystem path or a single module.
    32  func (m *Match) IsLocal() bool
    33  
    34  // IsMeta reports whether the pattern is a “meta-package” keyword that represents
    35  // multiple packages, such as "std", "cmd", or "all".
    36  func (m *Match) IsMeta() bool
    37  
    38  // IsMetaPackage checks if name is a reserved package name that expands to multiple packages.
    39  func IsMetaPackage(name string) bool
    40  
    41  // A MatchError indicates an error that occurred while attempting to match a
    42  // pattern.
    43  type MatchError struct {
    44  	Match *Match
    45  	Err   error
    46  }
    47  
    48  func (e *MatchError) Error() string
    49  
    50  func (e *MatchError) Unwrap() error
    51  
    52  // MatchPackages sets m.Pkgs to a non-nil slice containing all the packages that
    53  // can be found under the $GOPATH directories and $GOROOT that match the
    54  // pattern. The pattern must be either "all" (all packages), "std" (standard
    55  // packages), "cmd" (standard commands), or a path including "...".
    56  //
    57  // If any errors may have caused the set of packages to be incomplete,
    58  // MatchPackages appends those errors to m.Errs.
    59  func (m *Match) MatchPackages()
    60  
    61  // MatchDirs sets m.Dirs to a non-nil slice containing all directories that
    62  // potentially match a local pattern. The pattern must begin with an absolute
    63  // path, or "./", or "../". On Windows, the pattern may use slash or backslash
    64  // separators or a mix of both.
    65  //
    66  // If any errors may have caused the set of directories to be incomplete,
    67  // MatchDirs appends those errors to m.Errs.
    68  func (m *Match) MatchDirs(modRoots []string)
    69  
    70  // WarnUnmatched warns about patterns that didn't match any packages.
    71  func WarnUnmatched(matches []*Match)
    72  
    73  // ImportPaths returns the matching paths to use for the given command line.
    74  // It calls ImportPathsQuiet and then WarnUnmatched.
    75  func ImportPaths(patterns, modRoots []string) []*Match
    76  
    77  // ImportPathsQuiet is like ImportPaths but does not warn about patterns with no matches.
    78  func ImportPathsQuiet(patterns, modRoots []string) []*Match
    79  
    80  // CleanPatterns returns the patterns to use for the given command line. It
    81  // canonicalizes the patterns but does not evaluate any matches. For patterns
    82  // that are not local or absolute paths, it preserves text after '@' to avoid
    83  // modifying version queries.
    84  func CleanPatterns(patterns []string) []string
    85  
    86  // IsStandardImportPath reports whether $GOROOT/src/path should be considered
    87  // part of the standard distribution. For historical reasons we allow people to add
    88  // their own code to $GOROOT instead of using $GOPATH, but we assume that
    89  // code will start with a domain name (dot in the first element).
    90  //
    91  // Note that this function is meant to evaluate whether a directory found in GOROOT
    92  // should be treated as part of the standard library. It should not be used to decide
    93  // that a directory found in GOPATH should be rejected: directories in GOPATH
    94  // need not have dots in the first element, and they just take their chances
    95  // with future collisions in the standard library.
    96  func IsStandardImportPath(path string) bool
    97  
    98  // IsRelativePath reports whether pattern should be interpreted as a directory
    99  // path relative to the current directory, as opposed to a pattern matching
   100  // import paths.
   101  func IsRelativePath(pattern string) bool
   102  
   103  // InDir checks whether path is in the file tree rooted at dir.
   104  // If so, InDir returns an equivalent path relative to dir.
   105  // If not, InDir returns an empty string.
   106  // InDir makes some effort to succeed even in the presence of symbolic links.
   107  func InDir(path, dir string) string