How to run all .go files within current directory through the command line (multi file package)

前端 未结 11 2570
滥情空心
滥情空心 2020-12-08 01:49

I\'m a newcomer to Go. I extremely like the language, but I quickly realised that I needed to start dividing my files due to an increase in program size.

go r

11条回答
  •  鱼传尺愫
    2020-12-08 02:24

    The best way to do it is to run it like this:

    go run !(*_test).go
    

    It skips all your test files which is exactly what you need to avoid the error.

    The other suggestion:

    go build && ./
    

    is a bit annoying. You have to delete the executable all the time to avoid being marked by git. You can put it in gitignore, of course, but I am lazy and this is an extra step.

提交回复
热议问题