Skip to content

Commit

Permalink
Update 2023-12-03-syntax-and-structure-of-a-go-program.md
Browse files Browse the repository at this point in the history
  • Loading branch information
medojoe authored Dec 3, 2023
1 parent e30d752 commit 49a7af3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions _posts/2023-12-03-syntax-and-structure-of-a-go-program.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
layout: post
title: Installing Go (Golang)
categories: Golang
tags: [learn, Golang, Go, install]
---

# Syntax and Structure of a Go Program

![image](https://github.com/medojoe/medojoe.github.io/assets/24555193/d4674aaf-0efc-4dee-979b-52650ebe71e0)
Expand All @@ -8,15 +15,15 @@ Go, also known as Golang, is a popular programming language that has gained sign

Go has a straightforward and minimalist syntax that makes it easy to read and write code. Here are some essential syntax rules to keep in mind:

### 1. Package Declaration [1]
### 1. Package Declaration

Every Go program starts with a package declaration, which defines the package name. A package is a collection of related Go files that work together to achieve a common goal. For example, the main package is used to create an executable program.

```go
package main
```

### 2. Import Statements [1]
### 2. Import Statements

After the package declaration, you can include import statements to bring in other packages that your program depends on. This allows you to use functions, types, and variables defined in those packages.

Expand All @@ -27,7 +34,7 @@ import (
)
```

### 3. Main Function [1]
### 3. Main Function

The main function is the entry point of any Go program. It is where the execution of the program begins. Every executable program must have a main function.

Expand All @@ -37,7 +44,7 @@ func main() {
}
```

### 4. Comments [1]
### 4. Comments

Go supports both single-line and multi-line comments. Comments are used to document code and provide additional information. They are ignored by the compiler during the execution of the program.

Expand All @@ -50,7 +57,7 @@ Go supports both single-line and multi-line comments. Comments are used to docum
*/
```

### 5. Variables and Constants [1]
### 5. Variables and Constants

Go is a statically typed language, which means that variables must have a specific type assigned to them. Constants, on the other hand, are values that cannot be changed once assigned.

Expand All @@ -59,7 +66,7 @@ var age int = 25
const pi float64 = 3.14159
```

## Structure of a Go Program [1]
## Structure of a Go Program

A Go program consists of one or more source files, each with its own package declaration. Let's take a closer look at the structure of a typical Go program:

Expand Down

0 comments on commit 49a7af3

Please sign in to comment.