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

前端 未结 11 2582
滥情空心
滥情空心 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:26

    Unix related systems

    go run *.go will be sufficient in most cases.

    Continue to the below method if this causes errors.

    Windows systems (and in other cases where go run *.go doesn't work)

    Token expansion doesn't work in the windows command line and hence the above will not work and display an error. go run *.go may also not work in OSs in some cases due to current compiler limitations.

    In these cases, use

    go build && foo.exe

    where foo.exe is the name of the .exe file produced. If perhaps you have no idea what the name of your executable is, first

    go build and check the name of the .exe file produced. Afterwards, use the method that includes the file name.

    These 2 methods will build and run all the .go files within your current directory with minimum fuss.

提交回复
热议问题