About code under the examples folder and lib module

64 views
Skip to first unread message

Tong Sun

unread,
Aug 17, 2024, 12:36:11 AM8/17/24
to golang-nuts
Hi,

when providing a lib/module, would sample code under the `examples` folder be considered/linked as part of the module? I guess Go linker would be smart enough to not include them, as they all have their own `func main()` in them, but just want to clarify / confirm. 

I remember seeing one lib/module, which, in order not to let the examples affect the module package size, even put the `examples` folder under `internal/`.

All in all, what's the idiomatic way for Go modules to provide usage examples, everything under the same `examples` folder, or different packages having their own `examples` folders, or other ways? thx.


Brian Candler

unread,
Aug 17, 2024, 10:54:37 AM8/17/24
to golang-nuts
It's only going to compile/link packages which are referenced by an "import" statement (recursively).
Reply all
Reply to author
Forward
0 new messages