Back to Blog
Getting Started with Golang

1/30/20244 min read

Getting Started with Golang

Go (or Golang) is a statically typed, compiled programming language designed at Google. It's known for its simplicity, fast compilation, built-in concurrency, and efficient performance.

Note: Go compiles directly to native machine code, making it blazingly fast with no virtual machine overhead.

Features of Go

  • Simple and Clean Syntax
  • Fast Compilation
  • Built-in Concurrency (Goroutines & Channels)
  • Garbage Collection
  • Static Typing with Type Inference
  • Cross-Platform Support

Hello World Example

go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Basic Syntax

Variables

go
// Explicit type declaration
var age int = 25
var name string = "Alice"
var isStudent bool = true

// Short declaration (type inference)
age := 25
name := "Alice"
isStudent := true

Conditional Statement

go
if age > 18 {
    fmt.Println("Adult")
} else {
    fmt.Println("Minor")
}

Loops

go
// Traditional for loop
for i := 0; i < 5; i++ {
    fmt.Println("Iteration:", i)
}

// While-style loop
i := 0
for i < 5 {
    fmt.Println("Iteration:", i)
    i++
}

Go Struct and Methods

go
package main

import "fmt"

// Struct definition
type MyStruct struct {
    number int
}

// Constructor function
func NewMyStruct(num int) *MyStruct {
    return &MyStruct{number: num}
}

// Method
func (m *MyStruct) DisplayNumber() {
    fmt.Println("Number:", m.number)
}

Tip: Always follow naming conventions and keep your code readable!

Summary

Go is an excellent language for beginners and experienced developers alike, with its simple syntax, powerful concurrency features, and fast performance. Start building and enjoy the simplicity!

Other posts that might interest you...