#02 The Basic Structure of the Go file

Search for a command to run...

No comments yet. Be the first to comment.
I am learning the Go language and taking notes while learning in the easiest way from my side and in detail, I will just post here by Series.
Variable Variables are for storing data values. In Golang there are available data types for variables are string, int, boolean, and float32. There are 2 ways to declare the variable First way is to declare a variable using the var keyword Second ...
Variable Variables are for storing data values. In Golang there are available data types for variables are string, int, boolean, and float32. There are 2 ways to declare the variable First way is to declare a variable using the var keyword Second ...

Content Security Policy ( CSP ) CSP is a layer that helps to prevent certain types of attacks including Cross-Site Scripting ( XSS ) and data injection attacks. These types of attacks are used to deface websites and steal data. CSP is designed to be ...

Go language statically typed language, compiled programming language designed at Google. Infrastructure has changed a lot in years with cloud and multi-core processors. As it said the infrastructure is scalable & distributed, and dynamic has more cap...

Statically Typed Languages Statically typed language needs to define variable data type before compiling the program Because the compiler doesn’t understand the type of variable value whether it’s string or integer. Example: public class Main { p...

A go file has the following parts:
Example:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
package keyword defines the package name because every program is a part of the package, In the above code, I set the package name as main which will indicate that this package belongs to the main package.
import "fmt" used to import package function. Multiple packages can be imported using import ().
Example:
import (
"fmt"
"time"
)
func main() {
start := time.Now()
t := time.Now()
fmt.Println("Hello, 世界")
elapsed := t.Sub(start)
fmt.Printf("Time takes: %d\n", elapsed)
}
func main() {} is the entry point of Golang, According to Golang reference “The main package must have package name main and declare a function main that takes no arguments and returns no value.”
If I don’t write the main() function the code will not execute and return the output:
runtime.main_main·f: function main is undeclared in the main package.
fmt.Println("Hello World!") the “fmt” package is the standard library of Go, fmt package has I/O functions such as Printf(), Println(), Scanf() so on. To use print, scan and other I/O function fmt package will require.