Packages for platform-independent functionality
When you are building a command-line interface (CLI) that will be shared with the public, it’s important that the code is platform-independent to support users who are running the CLI on different operating systems. Golang has supportive packages that provide platform-independent interfaces to operating system functionality. A few of these packages include os
, time
, and path
. Another useful package is the runtime
package, which helps when detecting the operating system the application is running on, among other things. We will review each of these packages with some simple examples to show how to apply some of the available methods.
The os package
The operating system (os) package has a Unix-like design but applies uniformly across all operating systems. Think of all the operating system commands you can run in a shell, including external commands. The os
package is your go-to package. We discussed calling external commands...