Golang Cmd Essentials

Author

Reads 318

Programming Code on Laptop Screen
Credit: pexels.com, Programming Code on Laptop Screen

Golang's cmd package provides a way to create executable files that can be run from the command line.

The cmd package is a built-in package in Golang, which means you don't need to install anything extra to use it.

To use the cmd package, you need to import it in your code with `import "cmd/main"`.

Cmd Basics

You can run basic shell commands using the exec.Cmd instance, which runs the given command directly without spawning a shell. This means that any shell-based processing, like glob patterns or expansions, will not be done.

To run a command and read its output, create a new exec.Cmd instance and run it. For example, you can list the files in your current directory using ls and print the output from your code.

The cmd package in Go provides a way to run external commands with concurrent access to output and status. It wraps the os/exec.Command to correctly handle reading output while a command is running and killing a command.

Here are some basic examples of what you can do with the cmd package:

  • Run a command and print its output, like listing files in the current directory using ls.
  • Run a command and capture its output, like running env and printing its output.

Overview

Credit: youtube.com, Command Line Crash Course For Beginners | Terminal Commands

Cmd is a package in Go that allows you to run external commands while having concurrent access to their output and status.

It's designed to handle reading output while a command is running and killing a command, making it safe to call from multiple goroutines.

Cmd wraps the Go standard library's os/exec.Command to provide this functionality.

A basic example of using Cmd is running the env command and printing its output.

You can also use the Start method to run a command and receive its final status on a channel.

The first example in the documentation blocks on receiving the channel, while the second example is non-blocking and saves the channel to receive on later.

Only one final status is sent to the channel, so you can use the Done method to wait for the command to finish and then call Status to get the final status.

In addition to running commands, Go also has a tool for managing Go source code.

You can use the -n flag to print the commands that would be executed, and the -x flag to print the commands as they are executed.

Types

Stylish adult man using his smartphone for voice commands in an outdoor urban setting.
Credit: pexels.com, Stylish adult man using his smartphone for voice commands in an outdoor urban setting.

Types are an essential part of working with Cmd. The Options type represents customizations for NewCmdOptions.

The Options type has a Streaming property that determines whether a Cmd uses an OutputStream for STDOUT and STDERR. If Streaming is true, a Cmd will use an OutputStream for both STDOUT and STDERR when created by calling NewCmdOptions.

You can use OutputStream directly with a Go standard library os/exec.Command, but it requires careful management to avoid issues. A good solution is to use an OutputBuffer, which represents command output saved in an unbounded buffer.

An OutputBuffer is safe for multiple goroutines to read while the command is running and after it has finished. If output is small and not read frequently, an OutputBuffer is a good solution. To use an OutputBuffer with a Go standard library os/exec.Command, call stdout.Lines() while runnableCmd is running to read all output currently written.

Here's an interesting read: Golang Types

New

Creating a new Cmd is as easy as calling NewCmd. This function creates a new Cmd for the given command name and arguments, and the command isn't started until you call Start.

Adult male programmer working on code at a modern desk setup with a large monitor.
Credit: pexels.com, Adult male programmer working on code at a modern desk setup with a large monitor.

You can also create a new Cmd with options by using NewCmdOptions. This function does essentially the same thing as NewCmd, but it allows you to pass in options.

If you need to restart a Cmd, you'll want to clone it using the Clone method. This method creates a copy of the Cmd, but the internal state of the original object is lost. This is because a Cmd is one-use only, so you'll need to clone it if you want to run it again.

Done in 1.0.2

The Done method in the Cmd package was added in version 1.0.2, making it a relatively recent addition to the library.

This method returns a channel that's closed when the command stops running, providing a way for multiple goroutines to wait for the command to finish.

The Done method is useful for synchronizing goroutines that are waiting for a command to complete.

Initialize Module

Initializing a new module is a crucial step in setting up your Go project. You can use the `go mod init` command to create a new module in the current directory.

Focused woman coding on a laptop in a modern office setting.
Credit: pexels.com, Focused woman coding on a laptop in a modern office setting.

The `go mod init` command accepts an optional argument, the module path for the new module. If you omit this argument, init will attempt to infer the module path using import comments in .go files and the current directory.

You can also use the `-go` flag with `tidy` to update the 'go' directive in the `go.mod` file to a specific version. This can change which module dependencies are retained as explicit requirements in the `go.mod` file.

A recommended directory structure for your project includes a `go.mod` file in the root directory, which is initialized with the `go mod init` command. This file contains metadata about your project, including the module path and dependencies.

Here's a breakdown of the `go mod init` command:

The `go mod init` command is essential for creating a new module and managing dependencies in your Go project.

What's in the Main Package?

So, what goes into the main package? In general, it's best to keep it minimal and focused on user interaction. This includes command-line argument parsing, which is crucial for handling different options for a CLI client or server.

Vibrant close-up of a computer screen displaying color-coded programming code.
Credit: pexels.com, Vibrant close-up of a computer screen displaying color-coded programming code.

The main package is where you should put code that interacts with users of the resulting binary. This means parsing arguments, handling user input, and configuring the application.

Some examples of what to put in the main package include command-line argument parsing, user input, config file parsing, exit codes, and signal traps. These are all important aspects of user interaction that should be handled in the main package.

Here are some specific examples of what to put in the main package:

  • Command-line argument parsing
  • User input (if it's simple and not part of the core application logic)
  • Config file parsing
  • Exit codes
  • Signal Traps

Cmd Functions

The go-cmd/Cmd package provides a simple and safe way to run external commands in concurrent applications. It works on Linux, macOS, and Windows.

The basic usage of go-cmd/Cmd involves only three methods: Start, Stop, and Status. These methods are all you need to run and manage external commands.

Start immediately returns a channel to which the final status is sent when the command exits for any reason. This means commands run asynchronously by default, but synchronous execution is also possible.

Credit: youtube.com, Golang - Handling user input via Command Line Arguments (BUILD touch Clone)

To achieve similar functionality with os/exec.Cmd requires everything go-cmd/Cmd already does.

The go-cmd/Cmd package provides several benefits over os/exec.Cmd, including channel-based fire and forget, real-time stdout and stderr, and real-time status.

Here are the benefits of using go-cmd/Cmd over os/exec.Cmd:

  1. Channel-based fire and forget
  2. Real-time stdout and stderr
  3. Real-time status
  4. Complete and consolidated return
  5. Proper process termination
  6. 100% test coverage, no race conditions

The Status method can be called any time by any goroutine, and it returns a struct with all information about the command.

Cmd Execution

Cmd Execution is a breeze with go-cmd/Cmd. It's a small but very useful wrapper around os/exec.Cmd that makes it safe and simple to run external commands in highly concurrent, asynchronous, real-time applications.

It works on Linux, macOS, and Windows, and its basic usage is straightforward: just three methods: Start, Stop, and Status. go-cmd/Cmd provides channel-based fire and forget, real-time stdout and stderr, real-time status, complete and consolidated return, proper process termination, and 100% test coverage with no race conditions.

The Status method can be called any time by any goroutine, and it returns a struct that conveys all information about the command, including the final status sent to the status channel returned by the call to Start. This is a major improvement over Go's built-in Cmd, which doesn't put all the return information in one place.

Here are the benefits of using go-cmd/Cmd over os/exec.Cmd:

  • Channel-based fire and forget
  • Real-time stdout and stderr
  • Real-time status
  • Complete and consolidated return
  • Proper process termination
  • 100% test coverage, no race conditions

Run Specified Tool

Futuristic workspace featuring a glowing computer screen with coding displayed, ideal for technology and programming concepts.
Credit: pexels.com, Futuristic workspace featuring a glowing computer screen with coding displayed, ideal for technology and programming concepts.

Running a specified Go tool is a straightforward process. You can do this by simply typing 'go tool' followed by the arguments for the specific tool you want to run.

Go ships with a number of built-in tools, and you can find out what they are by running 'go tool' with no arguments. It will print the list of known tools.

The '-n' flag is a useful option when running a tool, as it allows you to see the command that would be executed without actually running it. This can be especially helpful for debugging purposes.

You can also use the '-modfile' flag to specify an alternate 'go.mod' file instead of the one in the module root directory. This can be useful if you're working on a project with a custom 'go.mod' file.

The '-C', '-overlay', and '-modcacherw' flags are also available for use with the 'go tool' command. For more information on each of these flags, you can refer to the documentation for the specific tool you're using.

For your interest: Golang Tools

Cmd Output

Credit: youtube.com, How to Capture Log Output in Golang While Executing a Command Efficiently

Cmd Output is a crucial aspect of working with the Go standard library's os/exec package. It's safe for multiple goroutines to read from an OutputBuffer while the command is running and after it has finished.

An OutputBuffer is a good solution when output is small and not read frequently, as it's unbounded and can handle a few megabytes of data. It's also safe for multiple goroutines to read from while the command is running.

To use an OutputBuffer directly with a Go standard library os/exec.Command, you can call stdout.Lines() while the runnableCmd is running to read all output currently written. This is a more efficient approach than reading from a pipe.

Real-Time Stdout and Stderr

Reading stdout and stderr in real-time is a common requirement when working with external commands. This can be achieved by using the go-cmd/Cmd package, which provides a safe and simple way to run external commands in highly concurrent, asynchronous, real-time applications.

Credit: youtube.com, Stderr Stdout and Stdin - How to Redirect them - Commands for Linux

The go-cmd/Cmd package works on Linux, macOS, and Windows, and provides a basic usage that is easy to understand. It has only three methods: Start, Stop, and Status. When possible, it's better to use go-cmd/Cmd than os/exec.Cmd because go-cmd/Cmd provides several benefits, including channel-based fire and forget, real-time stdout and stderr, and real-time status.

The common approach to reading stdout or stderr while the command is running is to call StdoutPipe and read from the provided io.ReadCloser. However, this approach is wrong because it causes a race condition and is not thread-safe. The proper solution is to set the io.Writer of Stdout, which requires further work to write while possibly N-many goroutines read. go-cmd/Cmd has done this work.

go-cmd/Cmd provides a solution to read stdout or stderr in real-time by setting the io.Writer of Stdout. This approach is thread-safe and non-racey, and allows for reading stdout or stderr while the command is running.

Here are the benefits of using go-cmd/Cmd for real-time stdout and stderr:

  • Channel-based fire and forget
  • Real-time stdout and stderr
  • Real-time status
  • Complete and consolidated return
  • Proper process termination
  • 100% test coverage, no race conditions

By using go-cmd/Cmd, you can easily read stdout or stderr in real-time and avoid the common pitfalls of using os/exec.Cmd.

Print Environment Information

Credit: youtube.com, How can I see environment variables in command prompt (CMD) or output them to a file

The go command has a built-in tool called env that prints Go environment information. You can use it to see what's going on behind the scenes.

By default, the env command prints information as a shell script. If you want to see the output in JSON format, you can use the -json flag.

If you give the env command one or more variable names as arguments, it will print the value of each named variable on its own line. The -u flag requires one or more arguments and unsets the default setting for the named environment variables, if one has been set with 'go env -w'.

The -w flag is used to change the default settings of the named environment variables to the given values. You can use it like this: 'go env -w NAME=VALUE'.

The -changed flag is used to print only those settings whose effective value differs from the default value that would be obtained in an empty environment with no prior uses of the -w flag.

The env command is a great tool for getting a sense of what's going on with your Go environment.

Cmd Status

Credit: youtube.com, go console commands | go cmd | cmd go | commands in go | go cli

Cmd Status is a crucial aspect of working with Go's cmd package. It allows you to retrieve the status of a command at any time, making it safe to call concurrently by multiple goroutines.

The Status method returns a Status object, which contains the command's status, including the output, runtime, and error. With buffered output, Status.Stdout and Status.Stderr contain the full output as of the Status call time.

You're responsible for tailing the buffered output if needed, or consider using streaming output instead. When the command finishes, the buffered output is complete and final, and you can use Status.Runtime to get the final value.

The Status type also has fields for StartTs and StopTs, which indicate whether the command has started or stopped. If StartTs > 0, the command has started, and if StopTs > 0, it has stopped.

After the command finishes, you can check the Error field to see if it failed to start or was terminated unexpectedly. If the error is nil, you can then check Exit and Complete to see if the command completed successfully.

Cmd Options

Credit: youtube.com, Go flag Module - Reading Command-Line Flags in Golang!

Cmd Options are a crucial part of the go-cmd/Cmd package, allowing you to customize how commands are run. The NewCmdOptions function creates a new Cmd with options, but the command isn't started until Start is called.

You can customize Cmd options using the Options type, which represents customizations for NewCmdOptions. For example, if you set Options.Streaming to true, a Cmd will use an OutputStream for both STDOUT and STDERR.

To use the OutputStream directly with a Go standard library os/exec.Command, you'll need to create a Cmd with Options.Streaming set to true. This will allow you to use the OutputStream as a custom output stream.

New Options

New options can be created with the NewCmdOptions function, which was added in version 1.0.1.

This function creates a new Cmd with options, but the command isn't started until the Start method is called.

You can use NewCmdOptions to create a new command with specific options, making it easier to manage and customize your commands.

The command won't run until you explicitly call the Start method, giving you more control over when and how your commands are executed.

Type Options

A professional woman working at her desk on a laptop, embodying focus and dedication.
Credit: pexels.com, A professional woman working at her desk on a laptop, embodying focus and dedication.

Type Options represents customizations for NewCmdOptions.

Options is used to create a Cmd with options, but the command isn't started until Start is called.

Options.Streaming is true when created by calling NewCmdOptions, which means a Cmd uses an OutputStream for both STDOUT and STDERR.

This is different from using an OutputStream directly with a Go standard library os/exec.Command.

Print Version

The Print Version option is a useful tool for Go developers.

You can use the Print Version option to print the build information for Go binary files.

The go version command reports the Go version used to build each of the named files. If no files are named on the command line, it prints its own version information.

You can also use the go version command to walk a directory, recursively, looking for recognized Go binaries and reporting their versions. If a directory is named, it does this automatically.

The -v flag causes go version to report unrecognized files found during a directory scan. This can be helpful for debugging purposes.

The -m flag causes go version to print each file's embedded module version information, when available.

Additional reading: Golang Build

Cmd Execution Control

Credit: youtube.com, Go Commands with os/exec | FFmpeg Utility #1

Cmd Execution Control is crucial for managing long-running or indefinite commands in your GoLang application.

By default, commands run asynchronously, but you can easily run them synchronously if needed.

To control the execution of long-running or indefinite commands, you can use a context instance. If the context gets cancelled, the command terminates as well. This is useful for limiting the time spent in running a command or creating a fallback in case a command doesn’t return a result on time.

Fire and Forget via Channel

go-cmd/Cmd provides a convenient way to run external commands in highly concurrent, asynchronous, real-time applications. It works on Linux, macOS, and Windows, and is a safer and simpler alternative to os/exec.Cmd.

Starting a command with go-cmd/Cmd immediately returns a channel to which the final status is sent when the command exits for any reason. This means that commands run asynchronously by default, but can also be run synchronously if needed.

Computer Program Language Text
Credit: pexels.com, Computer Program Language Text

Here are the benefits of using go-cmd/Cmd for fire and forget execution:

  1. Channel-based fire and forget
  2. Real-time stdout and stderr
  3. Real-time status
  4. Complete and consolidated return
  5. Proper process termination
  6. 100% test coverage, no race conditions

This makes it easy to write concurrent and asynchronous code that can handle external commands in a reliable and efficient way.

Proper Process Termination

Proper process termination is crucial when executing commands in Go. It's a common issue with os/exec.Cmd where Wait can block even after the command is killed, causing problems.

This is because os/exec.Cmd.Wait can block even after the command is killed, which can be surprising and cause problems. The issue has to do with process group IDs.

go-cmd/Cmd.Stop reliably terminates the command, no surprises. It implements the necessary low-level magic to make this happen. This is in contrast to os/exec.Cmd.Wait which can block even after the command is killed.

go-cmd/Cmd.Stop sends the process group a SIGTERM signal, which is the proper way to terminate a command. This is more reliable than killing the command PID, which is not always enough to terminate the process.

Here are the reasons why os/exec.Cmd.Wait can block even after the command is killed:

  1. Wait can block even after the command is killed.
  2. The issue has to do with process group IDs.

This can be avoided by using go-cmd/Cmd.Stop, which reliably terminates the command.

Cmd Compilation

Credit: youtube.com, Is There a Golang Terminal Shell? Exploring Compiled Language Possibilities

Cmd Compilation is a crucial step in the Go build process.

Cmds are compiled into binaries, which can be executed directly.

This compilation process involves several steps, including parsing the Go code, checking for errors, and generating machine code.

The Go compiler, known as go tool, takes care of this process efficiently.

Compile Packages

The go build command compiles packages and their dependencies, but it doesn't install the results.

Build ignores files that end in '_test.go' when compiling packages.

If you're compiling a single main package, build writes the resulting executable to an output file named after the last non-major-version component of the package import path.

The '.exe' suffix is added when writing a Windows executable.

The executable is named after the first source file when compiling a package from a list of .go files.

The -o flag forces build to write the resulting executable or object to the named output file or directory.

Credit: youtube.com, Compiling From Command Prompt large

You can use the -o flag to specify a custom name for the executable or object.

The build flags are shared by the build, clean, get, install, list, run, and test commands.

The -gcflags, -ldflags flags accept a space-separated list of arguments to pass to an underlying tool during the build.

These flags can be used to specify different arguments for different sets of packages.

Note that build adheres to certain conventions, but not all projects can follow these conventions.

Split Entry Point from App Code

Having the entry-point code separate from the application code is a best practice in Go development. This is because the entry-point code, which includes the main() function, is meant to be the starting point of the application, not the core logic.

The main() function is executed first when the application starts, and it's tempting to put all the core application functionality within it. However, this can make testing harder.

Workplace with modern laptop with program code on screen
Credit: pexels.com, Workplace with modern laptop with program code on screen

The official os/exec package allows us to run external commands, which are run as child processes within the running Go application. This means that each command is executed independently, exposing Stdin and Stdout attributes that we can use to read and write data from the process.

Having the application code in a separate package, like an app package, makes testing easier. This is because we can create Start() and Stop() or Shutdown() functions for the app package, making it easier to write tests that execute against the core logic.

The app package recommendation is especially useful for command-line projects that are both servers and CLI clients. By having the application code in a shared package, both the server and the CLI client can share this core app package.

Worth a look: Golang Cli

Cmd Build and Install

The 'go build' and 'go install' commands take a -json flag that reports build output and failures as structured JSON output on standard output. This JSON stream is a newline-separated sequence of BuildEvent objects, each corresponding to the Go struct.

Credit: youtube.com, Build Your First Command Line Tool in Go

The ImportPath field of a BuildEvent gives the package ID of the package being built, matching the Package.ImportPath field of go list -json and the TestEvent.FailedBuild field of go test -json. The Action field is one of several possible values, including "build-output", which indicates that the Output field is set.

For "build-output" events, the Output field contains a portion of the build's output, which can be concatenated with the Output fields of other events to reconstruct the exact output of the build. This is useful for parsers that need to distinguish between test and build events, and can simply concatenate the Output fields of all events to reconstruct the text format output.

Discover more: Fields Golang

Build and Validate Caching

The go command caches build outputs for reuse in future builds, storing them in a subdirectory named go-build in the standard user cache directory.

This cache is safe for concurrent invocations of the go command, and you can override the default location by setting the GOCACHE environment variable.

Close-up of a computer screen displaying colorful programming code with depth of field.
Credit: pexels.com, Close-up of a computer screen displaying colorful programming code with depth of field.

Running 'go env GOCACHE' prints the current cache directory, and the cache is periodically deleted if it hasn't been used recently.

However, if you've made changes to C libraries imported with cgo, you'll need to clean the cache explicitly or use the -a build flag to force rebuilding of packages that depend on the updated libraries.

The go command also caches successful package test results, and you can remove all cached test results by running 'go clean -testcache'.

The go command caches values used in fuzzing with 'go test -fuzz', and you can remove all cached fuzzing values by running 'go clean -fuzzcache'.

You might like: Golang Test Framework

Compile and Install Packages

The 'go install' command compiles and installs packages and dependencies. It installs executables in the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set.

To install executables without affecting the dependencies of the main module, use the 'go install' command with version suffixes like @latest or @v1.0.0, which runs in module-aware mode.

CSS code displayed on a computer screen highlighting programming concepts and technology.
Credit: pexels.com, CSS code displayed on a computer screen highlighting programming concepts and technology.

In module-aware mode, the 'go install' command ignores the go.mod file in the current directory or any parent directory, if there is one. This is useful for installing executables without affecting the dependencies of the main module.

The 'go install' command can run in either GOPATH mode or module-aware mode, depending on the GO111MODULE environment variable and the presence of a go.mod file. If module-aware mode is enabled, the 'go install' command runs in the context of the main module.

Non-main packages are installed in the directory $GOPATH/pkg/$GOOS_$GOARCH when module-aware mode is disabled.

Here's an interesting read: Golang Mode

Cmd Testing

Cmd testing is an essential part of the Golang development process.

Cmd testing allows you to test your command-line tools and executables in isolation, which is crucial for ensuring they work correctly.

You can use the `go test` command to run tests for your cmd, just like you would for any other Go package.

This makes it easy to write and run tests for your cmd, which can help you catch bugs and ensure your code is working as expected.

Update Packages for New APIs

A focused developer coding at a modern office with dual monitors, showcasing a tech-driven workspace.
Credit: pexels.com, A focused developer coding at a modern office with dual monitors, showcasing a tech-driven workspace.

Updating packages for new APIs is a crucial step in ensuring your code remains compatible with the latest Go features. The Go fix command is used to update packages to use new APIs.

You can run the Go fix command using the fix command, which is part of the Go tool. The -fix flag sets a comma-separated list of fixes to run, with all known fixes being the default.

The value of the -fix flag is passed to 'go tool fix -r', which is a command that runs the fix tool recursively. This means you can easily update multiple packages at once.

For more information about the fix command, see 'go doc cmd/fix'. This will provide you with more details about how to use the fix command and what options are available.

The Go fix command is particularly useful when working with packages that use deprecated APIs. By running the fix command, you can update these packages to use the latest APIs and avoid any potential compatibility issues.

Test Packages

Credit: youtube.com, Why Tests Run via CMD is Essential?

Test Packages are a crucial part of Cmd testing, allowing you to run multiple tests at once and save time.

You can create a test package by specifying a group of tests to run together, making it easier to manage complex testing scenarios.

Cmd provides a built-in way to create test packages through the use of the `--package` flag.

For example, if you have multiple test files in a directory, you can run all the tests in that directory by using the `--package` flag along with the directory path.

This can be particularly useful when testing large codebases or complex systems.

Cmd's test packages also support filtering tests by name, which can be done using the `--filter` flag.

By using the `--filter` flag, you can specify a pattern to match against test names, allowing you to run only the tests that match the specified pattern.

For your interest: Golang Filter

Testing Flags

Testing flags are used to control the execution of any test, and several flags are recognized by the 'go test' command.

Male programmers working on computers in a modern office setting, showcasing teamwork and technology.
Credit: pexels.com, Male programmers working on computers in a modern office setting, showcasing teamwork and technology.

The --alloc_space, --alloc_objects, and --show_bytes options of pprof control how the information is presented.

Several flags control profiling and write an execution profile suitable for "go tool pprof"; run "go tool pprof -h" for more information.

The 'go test' command rewrites or removes recognized flags, as appropriate, both before and after the optional package list, before invoking the test binary.

The command "go test -c -x -v" will compile the test binary and then run it as "go test -c -test.v -v", removing the -x flag because it applies only to the go command's execution, not to the test itself.

The test flags that generate profiles (other than for coverage) also leave the test binary in pkg.test for use when analyzing the profiles.

When invoking a generated test binary directly, it may be necessary to do the same as when 'go test' runs a test binary, running it from within the corresponding package's source code directory.

The command-line package list, if present, must appear before any flag not known to the go test command.

To disable test caching, use any test flag or argument other than the cacheable flags, or use the idiomatic way to disable test caching explicitly by using -count=1.

Additional reading: Golang Binary

Star Status

Credit: youtube.com, This Makes Golang CLI Development So MUCH Better

You can get the status of a command at any time with the Status function, which is safe to call concurrently by multiple goroutines.

The Status function returns the current status of the command, including the output and runtime. This is useful for monitoring the command's progress and any errors that may occur.

The output of the command is buffered, so Status.Stdout and Status.Stderr contain the full output as of the Status call time. If you need to see the most up-to-date output, you'll need to tail the buffered output.

The Runtime field of the Status is updated while the command runs and is final when it finishes. This means you can use it to determine how long the command has been running.

Frequently Asked Questions

How to use Go on cmd?

To use Go on the command line, navigate to your home directory, create a new directory for your project, and then create a file called hello.go with the basic Go code. This will get you started with writing and running your first Go program.

How to check golang version in cmd?

To check the Go version in the Command Prompt, type `go version` and press Enter. This will display the installed version of Go.

Nancy Rath

Copy Editor

Nancy Rath is a meticulous and detail-oriented Copy Editor with a passion for refining written content. With a keen eye for grammar, syntax, and style, she has honed her skills in ensuring that articles are polished and engaging. Her expertise spans a range of categories, including digital presentation design, where she has a particular interest in the intersection of visual and written communication.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.