Stop the go mod tool from parsing certain directories
Asked Answered
C

1

16

I am using a mono repo and I download certain tools under the project tree (istio). Running go get -u or go mod tidy causes the main go.mod to get updated with irrelevant deps.

How do I exclude certain src subpaths for consideration.

Note:

This does not do the trick as the subdirectories I want to exclude do have go files in them.

Castaway answered 23/8, 2019 at 16:16 Comment(4)
Directory names starting with underscore are ignored by the Go tools.Stablish
@Stablish Where is that documented? I'm having a hard time finding an authoritative reference.Brigidbrigida
@JonathonReinhart, "Directory and file names that begin with '.' or '_' are ignored by the go tool, as are directories named 'testdata'." pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns, last paragraph.Stablish
@peter Perfect, thanks! I thought this behavior was specific to go modules; I didn't realize it applied to the entire go tool.Brigidbrigida
E
22

I think your two main options are:

  1. A go.mod in a directory will cause that directory and all of its subdirectories to be excluded from the top-level Go module.

  2. Use a leading underscore as Peter suggested, or a leading ..

If neither of those are appropriate, please add a comment explaining why, ideally including an error message or some other set of details about what happened when you tried.

Everglades answered 27/8, 2019 at 0:50 Comment(1)
I have a docker container and I have mapped the postgres directory to ./postgres_data and I don't want go.mod to index that directory as it is not accessible a normal user How do I do that. Currently I am using a workaround where I use an _ in the mapping but is there a way to do soViolaceous

© 2022 - 2024 — McMap. All rights reserved.