Go Programming Language (Introduction) (original) (raw)

Last Updated : 4 Sep, 2025

**Go, often referred to as **Golang, is an open-source programming language developed by Google in 2007 and officially released in 2009. It was designed with the goal of combining performance and security of a low-level language like C with the simplicity and productivity of modern languages like Python.

If you're looking to learn Go programming,**Boot.dev's Full Go Course is the perfect starting point. With step-by-step lessons, hands-on challenges, and expert guidance, you'll build a solid foundation in Go. Dive into real-world projects and gain the skills to become a proficient Go developer. Enroll now and master Go at your own pace!.

Hello World! Program in Golang

To run a Go program you need a Go compiler. In Go compiler, first you create a program and save your program with extension ****.go**, for example, **first.go.

Go `

// First Go program package main

import "fmt"

// Main function func main() {

fmt.Println("Hello, geeksforgeeks")

}

`

**Output:

Hello, geeksforgeeks

**Explanation of the syntax of Go program:

**Single Line Comment:

**Syntax:

// single line comment

**Multi-line Comment:

**Syntax:

/* multiline comment */

Now we run this **first.go file in the go compiler using the following command, i.e:

go run first.go

outgo

For more details about the different terms used in this program, you can visit Hello World in Golang

**Beginning with Go programming:

There are various online IDEs such as The Go Playground, repl.it, etc. which can be used to run Go programs without installing. For installing Go in own PCs or Laptop we need of following two software: Text editor and Compiler.

Note: Extension of source code file of go language must be ****.go**

Identifiers and Keywords

Identifiers are the user-defined name of the program components. In Go Programming language, an identifier can be a variable name, function name, constant, statement labels, package name, or types.

**Example:

// Valid identifiers: _geeks23 geeks gek23sd Geeks geeKs geeks_geeks

// Invalid identifiers: 212geeks if default

Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as an identifier. Doing this will result in a compile-time error. There are **total 25 keywords present in the Go language as follows:

Golang-Keywords

**Example:

Go `

// Go program to illustrate // the use of keywords

// Here package keyword is used to // include the main package // in the program package main

// import keyword is used to // import "fmt" in your package import "fmt"

// func is used to // create function func main() {

// Here, var keyword is used 
// to create variables
// Pname, Lname, and Cname 
// are the valid identifiers
var Pname = "GeeksforGeeks" 
var Lname = "Go Language" 
var Cname = "Keywords"

fmt.Printf("Portal name: %s", Pname)
fmt.Printf("\nLanguage name: %s", Lname)
fmt.Printf("\nChapter name: %s", Cname)

}

`

**Output:

Portal name: GeeksforGeeks Language name: Go Language Chapter name: Keywords

Data Types

Data types specify the type of data that a valid Go variable can hold. In Go language, the type is divided into four categories which are as follows:

  1. **Basic type: Numbers, strings, and booleans come under this category.
  2. **Aggregate type: Array and structs come under this category.
  3. **Reference type: Pointers, slices, maps, functions, and channels come under this category.
  4. **Interface type: Interfaces in Go define a set of method signatures that a type must implement. They allow you to write flexible and reusable code by focusing on _behavior rather than _specific implementation.

Here, we will discuss Basic Data Types in the Go language. The **Basic Data Types are further categorized into three subcategories which are:

  1. **Numbers
  2. **Booleans
  3. **Strings

**Numbers: In Go language, numbers are divided into three sub-categories that are:

Golang-Integers

**Floating-Point Numbers: In Go language, floating-point numbers are divided into **two categories as shown in the below table:

Golang-Floating-Point-Numbers

**Complex Numbers: The complex numbers are divided into two parts are shown in the below table. float32 and float64 are also part of these complex numbers. The in-built function creates a complex number from its imaginary and real part and in-built imaginary and real function extract those parts.

Golang-Complex-Numbers

Variable names must begin with a letter or an underscore(_). And the names may contain the letters ‘a-z’ or ’A-Z’ or digits 0-9 as well as the character ‘_’.

Geeks, geeks, _geeks23 // valid variable 123Geeks, 23geeks // invalid variable

234geeks // illegal variable

geeks and Geeks are two different variables

Conditional Structures

if : It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is _true then a block of statement is executed otherwise not.

**Syntax:

if(condition) {

// Statements to execute if // condition is true }

**Flow Chart:

edfghn

if-else : if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.

**Syntax:

if (condition) {

// Executes this block if
// condition is true

} else {

// Executes this block if
// condition is false

}

**Flow Chart:

fgoiuj

Nested if : Nested if statements mean an if statement inside an if statement. Yes, Golang allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.

**Syntax:

if (condition1) {

// Executes when condition1 is true

if (condition2) {

  // Executes when condition2 is true

} }

**Flow Chart:

tgbrfv

if-else-if Ladder : Here, a user can decide among multiple options. The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.

**Some popular Applications developed in Go Language