I've created an SDK that will be used for some different clients. This SDK has a structure similar to this:
- sdk-go
- .github
- config
- test1(folder)
- util
- .gitignore
- go.mod
- README.md
- service.go
- service_test.go
Basically when a client wants to use this SDK the only thing it has to do is to add the dependency in the mod.go file just like this:
require (
github.com/sdk v1.0.0
)
With that the module is added as a dependency in the external libraries.
I would like to exclude some files from the SDK and when the SDK is added as a library those files should not appears. For example, the .gitignore
file, service_test.go
, test1
folder but I don't know if that is possible.
I've tried some things in the SDK, for example, I've added a build constraint in the files I want to exclude in the SDK at the top of the file, but It didn't work. Just like this:
//go:build ignore
// +build ignore
Is there a way to exclude files from the SDK module?
Go does not have any mechanism for excluding files at module download. The build constraints you mentioned have no effect on module downloading; they only affect the build process.
The files you listed (a .gitignore
file, a test file, and a test folder) seem utterly harmless, so the easiest option is to not do anything about it. In fact, having such files in a downloaded module is quite normal. Especially, there is no point in excluding tests from published modules, as the module users might want to run the tests themselves.
If you really, desperately want to exclude files from a published module, consider using Git branches for publishing, in which you remove the files. (Ugly.) Or use separate repositories (also ugly).
TL;DR: Leaving the files in the repo won't hurt anybody, as they won't impact module use.