@@ -476,6 +476,7 @@ GoMod = { Directive } .
476476Directive = ModuleDirective |
477477 GoDirective |
478478 ToolDirective |
479+ IgnoreDirective |
479480 RequireDirective |
480481 ExcludeDirective |
481482 ReplaceDirective |
@@ -749,6 +750,36 @@ tool (
749750)
750751```
751752
753+ ### ` ignore ` directive {#go-mod-file-ignore}
754+
755+ An ` ignore ` directive will cause the go command ignore the slash-separated
756+ directory paths, and any files or directories recursively contained in them,
757+ when matching package patterns.
758+
759+ If the path starts with ` ./ ` , the path is interpreted relative to the
760+ module root directory, and that directory and any directories or files
761+ recursively contained in it will be ignored when matching package patterns.
762+
763+ Otherwise, any directories with the path at any depth in the module, and
764+ any directories or files recursively contained in them will be ignored.
765+
766+ ```
767+ IgnoreDirective = "ignore" ( IgnoreSpec | "(" newline { IgnoreSpec } ")" newline ) .
768+ IgnoreSpec = RelativeFilePath newline .
769+ RelativeFilePath = /* slash-separated relative file path */ .
770+ ```
771+
772+ Example
773+ ```
774+ ignore ./node_modules
775+
776+ ignore (
777+ static
778+ content/html
779+ ./third_party/javascript
780+ )
781+ ```
782+
752783### ` exclude ` directive {#go-mod-file-exclude}
753784
754785An ` exclude ` directive prevents a module version from being loaded by the ` go `
@@ -1850,7 +1881,7 @@ arguments must satisfy the following constraints:
18501881
18511882* Arguments must be package paths or package patterns (with "` ... ` " wildcards).
18521883 They must not be standard packages (like ` fmt ` ), meta-patterns (` std ` , ` cmd ` ,
1853- ` all ` ), or relative or absolute file paths.
1884+ ` all ` , ` work ` , ` tool ` ), or relative or absolute file paths.
18541885* All arguments must have the same version suffix. Different queries are not
18551886 allowed, even if they refer to the same version.
18561887* All arguments must refer to packages in the same module at the same version.
@@ -3167,13 +3198,15 @@ avoid confusing the `go` command's restricted parser. In particular, it should
31673198appear before any raw JavaScript or CSS. The ` <meta> ` tag must have the form:
31683199
31693200```
3170- <meta name="go-import" content="root-path vcs repo-url">
3201+ <meta name="go-import" content="root-path vcs repo-url [subdirectory] ">
31713202```
31723203
31733204` root-path ` is the repository root path, the portion of the module path that
3174- corresponds to the repository's root directory. It must be a prefix or an exact
3175- match of the requested module path. If it's not an exact match, another request
3176- is made for the prefix to verify the ` <meta> ` tags match.
3205+ corresponds to the repository's root directory, or to the ` subdirectory ` ,
3206+ if present and using Go 1.25 or later (see the section on ` subdirectory ` below).
3207+ It must be a prefix or an exact match of the requested module path. If it's
3208+ not an exact match, another request is made for the prefix to verify the ` <meta> `
3209+ tags match.
31773210
31783211` vcs ` is the version control system. It must be one of the tools listed in the
31793212table below or the keyword ` mod ` , which instructs the ` go ` command to download
@@ -3188,6 +3221,13 @@ control system. For example, with Git, the `go` command will try `https://` then
31883221` git+ssh:// ` . Insecure protocols (like ` http:// ` and ` git:// ` ) may only be used
31893222if the module path is matched by the ` GOINSECURE ` environment variable.
31903223
3224+ ` subdirectory ` , if present, is the slash-separated subdirectory of the repository
3225+ that the ` root-path ` corresponds to, overriding the default of the repository's
3226+ root directory. ` go-import ` meta tags providing a ` subdirectory ` are only recognized
3227+ by Go 1.25 and later. Attempts to fetch resolve modules on earlier versions of
3228+ Go will ignore the meta tag and result in a resolution failure if the module can
3229+ not be resolved elsewhere.
3230+
31913231<table id =" vcs-support " class =" ModTable " >
31923232 <thead >
31933233 <tr>
0 commit comments