What is Golang?

I started deep learning on golang. Today I learned some more Topics. * Golang Environment Setup * Init Golang Sample project Prerequisites * Some programming experience is required. The code is straightforward, but understanding functions is advantageous. * An editor for your code. You can use any text editor you have. Most text editors have good Go support. VSCode (free), GoLand (paid), and Vim are the most popular (free). * A command and control terminal. Go works well in any Linux

Alienx
3 min readJul 7, 2022

I started deep learning on golang.

Today I learned some more Topics.

  • Golang Environment Setup
  • Init Golang Sample project

Prerequisites

  • Some programming experience is required. The code is straightforward, but understanding functions is advantageous.
  • An editor for your code. You can use any text editor you have. Most text editors have good Go support. VSCode (free), GoLand (paid), and Vim are the most popular (free).
  • A command and control terminal. Go works well in any Linux or Mac terminal, as well as PowerShell or cmd in Windows.

Golang Environment Setup

Step (1) :-

Download Golang

Other steps are in this article here

Init Golang Sample project

Get started with Hello, World.

  1. Open a command prompt and cd to your home directory.

On Linux or Mac:cd

On Windows:cd %HOMEPATH%

  1. Create a hello directory for your first Go source code.

For example, use the following commands:mkdir hello cd hello

  1. Enable dependency tracking for your code.

When your code imports packages from other modules, you manage those dependencies in your own module. A go.mod file defines that module, which tracks the modules that provide those packages. That go.mod file is stored alongside your code, including in your source code repository.

Run the go mod init command, giving it the name of the module your code will be in, to enable dependency tracking for your code by creating a go.mod file. The module path is represented by the name.

In practise, the module path is usually the repository location where your source code is kept. For instance, the module path could be github.com/mymodule. If you intend to make your module available to others, the module path must point to a location where Go tools can download it. See Managing dependencies for more information on naming a module with a module path.

Just utilise example/hello for this tutorial’s needs. Go to the command line and type

$ go mod init example/hello to create a new Go.mod module.

Make a file called hello.go in your text editor and enter your code there.
Add the next piece of code to your greeting.
Save the file by going to file.

``` import “fmt” func main() { fmt.Println(“Hello, World!”) }```

This is your Go code. In this code, you:

  • Declare a main package (a package is a way to group functions, and it's made up of all the files in the same directory).
  • Import the popular fmt package, which contains functions for formatting text, including printing to the console. This package is one of the standard library packages you got when you installed Go.
  • Implement a main function to print a message to the console. A main function executes by default when you run the main package.

Run your code to see the greeting.$ go run . Hello, World!

The go run command is one of many go commands you'll use to get things done with Go. Use the following command to get a list of the others:$ go help

Other Coming Soon…🔜

Feedback

--

--