I've got a Go library that I'd like to distribute. It's got 62 source files, but I'd like to keep the API in a single package. Is there a way I can use multiple directories for code in a single package? It's not a huge amount of source, as the source files themselves are small, and I'd like to keep it that way if possible to make it navigable.
Since it was modeled after similar libraries in other languages, It's currently got two packages: /project and /project/models. After learning more about Go packaging I now realize that this is unwieldy for distribution and use. The user would prefer a single package.
Is there a "gopheric" way of doing this?
Read this two articles to have a good understanding of the best practices:
Each path directory can be a separate module/package in your app:
github.com/myaccount/myapp/
README.md
Makefile
applib/
cmd/
main.go
main_test.go
handlers.go
handlers_test.go
lib1/
main.go
main_test.go
process.go
process_test.go
lib2/
foo.go
foo_test.go
bar.go
bar_test.go
No, it is dead simple: One directory == one package. But having some kind of "main" package with "helper" packages in subdirectories is not really "unwieldy for distribution" as go get
handles this very well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With