How do go modules work with installable commands?

前端 未结 4 1220
悲&欢浪女
悲&欢浪女 2020-12-19 05:50

I\'ve recently started with Go 1.11 and love the modules. Apart from runtime dependencies I need to work with go modules during the build, e.g. during go generate

4条回答
  •  清酒与你
    2020-12-19 06:38

    https://github.com/golang/go/issues/25922 proved helpful for me, especially

    when using build-only dependencies with modules the main point is version selection (not installing these!)

    To avoid installing you can modify your //go:generate directive to something like:

    //go:generate go run golang.org/x/tools/cmd/stringer ARGS
    

    There is also the best practices repo: https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md

提交回复
热议问题