Text file src/README.vendor

     1  Vendoring in std and cmd
     2  ========================
     3  
     4  The Go command maintains copies of external packages needed by the
     5  standard library in the src/vendor and src/cmd/vendor directories.
     6  
     7  In GOPATH mode, imports of vendored packages are resolved to these
     8  directories following normal vendor directory logic
     9  (see golang.org/s/go15vendor).
    10  
    11  In module mode, std and cmd are modules (defined in src/go.mod and
    12  src/cmd/go.mod). When a package outside std or cmd is imported
    13  by a package inside std or cmd, the import path is interpreted
    14  as if it had a "vendor/" prefix. For example, within "crypto/tls",
    15  an import of "golang.org/x/crypto/cryptobyte" resolves to
    16  "vendor/golang.org/x/crypto/cryptobyte". When a package with the
    17  same path is imported from a package outside std or cmd, it will
    18  be resolved normally. Consequently, a binary may be built with two
    19  copies of a package at different versions if the package is
    20  imported normally and vendored by the standard library.
    21  
    22  Vendored packages are internally renamed with a "vendor/" prefix
    23  to preserve the invariant that all packages have distinct paths.
    24  This is necessary to avoid compiler and linker conflicts. Adding
    25  a "vendor/" prefix also maintains the invariant that standard
    26  library packages begin with a dotless path element.
    27  
    28  The module requirements of std and cmd do not influence version
    29  selection in other modules. They are only considered when running
    30  module commands like 'go get' and 'go mod vendor' from a directory
    31  in GOROOT/src.
    32  
    33  Maintaining vendor directories
    34  ==============================
    35  
    36  Before updating vendor directories, ensure that module mode is enabled.
    37  Make sure GO111MODULE=off is not set ('on' or 'auto' should work).
    38  
    39  Requirements may be added, updated, and removed with 'go get'.
    40  The vendor directory may be updated with 'go mod vendor'.
    41  A typical sequence might be:
    42  
    43      cd src
    44      go get -d golang.org/x/net@latest
    45      go mod tidy
    46      go mod vendor
    47  
    48  Use caution when passing '-u' to 'go get'. The '-u' flag updates
    49  modules providing all transitively imported packages, not only
    50  the module providing the target package.
    51  
    52  Note that 'go mod vendor' only copies packages that are transitively
    53  imported by packages in the current module. If a new package is needed,
    54  it should be imported before running 'go mod vendor'.
    55  

View as plain text