GOLang Structure | "Hello World" Program | In Hindi | Day #1

Опубликовано: 24 Март 2026
на канале: 5 Minutes Programming
125
2

In Go (or Golang), the structure of a program typically follows a specific pattern, consisting of packages, imports, declarations, and statements. Let's break down the structure of a basic Go program:

1. *Package Declaration:*
Every Go source file starts with a package declaration.
Packages are used to organize code into reusable units.
The `package` keyword followed by the package name is used to declare a package.
Example: `package main`

2. *Imports:*
After the package declaration, import statements are used to import packages from the Go standard library or external packages.
The `import` keyword followed by the package path is used to import packages.
Multiple import statements can be used, each importing a different package.
Example: `import "fmt"`

3. *Declarations:*
Go programs consist of declarations that define various elements such as functions, variables, types, and constants.
Function declarations, variable declarations, type declarations, and constant declarations are common in Go programs.
Example:
```go
var message string = "Hello, World!"
```

4. *Main Function:*
A Go executable program must contain a `main` function, which serves as the entry point of the program.
The `main` function is where execution begins when the program is run.
The `main` function is declared using the `func` keyword followed by the function name `main`.
Example:
```go
func main() {
fmt.Println(message)
}
```

5. *Statements:*
Statements are instructions that perform actions when executed.
Statements can include function calls, variable assignments, control flow statements (if, for, switch), and more.
Example:
```go
fmt.Println("Hello, World!")
```

6. *Comments:*
Comments are used to document code and provide additional context or explanations.
Single-line comments start with `//`, and multiline comments are enclosed between `/*` and `*/`.
Comments are ignored by the Go compiler and do not affect the program's behavior.
Example:
```go
// This is a single-line comment

/*
This is a multiline comment
spanning multiple lines
*/
```

7. *Whitespace and Formatting:*
Go is whitespace-sensitive, meaning indentation and spacing are used to structure code.
Proper formatting and indentation improve code readability and maintainability.
Go programs are conventionally formatted using the `gofmt` tool or integrated development environments (IDEs) with built-in formatting support.

Overall, the structure of a Go program follows a clear and concise pattern, emphasizing simplicity, readability, and maintainability. Understanding the basic structure of Go programs is essential for writing clean and effective code in the Go programming language.