Introduction to GoLanguage
Golang is an open-source web development language that was created by Google. This language has gained immense fame because of its top-notch security, concurrency and user-friendliness.
buymeacoffee ☕ 👈 Click the link
Features of Go Language
- Simplicity and Readability
- Concurrency Support
- Fast Compilation
- Static Typing
- Garbage Collection
- Standard Library
- Cross-Platform
- Tools and Ecosystem
UseCases
- Web Development
- Cloud and Network Services
- DevOps and Tooling
- Data Processing
Refer the installation guide
Download the Setup
Redirect the page
Installation done. Check Go version
go version
Write a sample “Hello-World” Program
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Run a code
Basic Go language syntax & types
Packages
Imports
Functions
Variables
Control Structure
Error Handling
Every Go file starts with a package declaration, which provides a way for code to be reused. The main package is the starting point of a Go program.
packages main
This is where you include code from the other packages. The fmt package, for example, is commonly used for formatted I/O.
import "fmt"
Functions are declared with the fmt keyword. The main functions is the entry point of a Go program.
func main() {
fmt.Println("Hello-World")
}
Variable can be declared using the var keyword, but also allows for short variable declaration with :=.
var x int = 10
y := 20 // short declaration
Go has control structure like if, for, switch, but no while (or) do while
for i := 0; i < 10; i++ {
fmt.Println(i)
}
Go handles error by returning an error type as a part of the functions return value.
func sqrt(x float64) (float64, error) {
if x < 0 {
return 0, errors.new("negative value")
}
return math.sqart(x), Nil
}
Types
Includes integers (int, uint, int8, uint8) floating points (float32, float64) complex numbers (complex64, complex128) boolean (bool)
Composite Types
Arrays → Fixed size list of elements of the same type
Slices → Dynamically sized, flexible view into the elements of anarray
Structs → Clooection of fields
Maps → Collection of Key-Value pairs
Thank you 🙏 for taking the time to read our blog.