Courses/Go/Introduction to Go

    Lesson 1 • Beginner

    Introduction to Go 🐹

    Discover why Google created Go, what makes it unique among programming languages, and write your very first Go program.

    What You'll Learn in This Lesson

    • • What Go is and why Google built it
    • • Go's design philosophy: simplicity, speed, concurrency
    • • Setting up Go and creating a project with go mod
    • • Basic syntax, packages, and the fmt package
    • • Public vs private naming convention

    1️⃣ What is Go?

    Go (also called Golang) was created at Google in 2009 to solve real problems: slow compile times in C++, complex dependency management, and difficulty writing concurrent programs. Go compiles to a single native binary — no runtime needed — and starts up in milliseconds. It powers Docker, Kubernetes, and most of modern cloud infrastructure.

    Try It: Hello Go

    Your first Go program and why Go is special

    Try it Yourself »
    JavaScript
    // Your First Go Program — simulated in JavaScript
    console.log("=== Hello, Go! ===");
    console.log();
    
    // In Go you write:
    // package main
    // import "fmt"
    // func main() {
    //     fmt.Println("Hello, World!")
    // }
    
    console.log("package main");
    console.log('import "fmt"');
    console.log();
    console.log("func main() {");
    console.log('    fmt.Println("Hello, World!")');
    console.log("}");
    console.log();
    console.log("Output: Hello, World!");
    console.log();
    
    console.log("=== Why Go? ===");
    console.log("Cre
    ...

    2️⃣ Setting Up Go

    Go has excellent tooling built right in. go mod init creates a project, go run executes code, go build compiles a binary, and go fmt formats your code automatically — ending all style debates.

    Try It: Setup & Tools

    Install Go, create a project, and explore the toolchain

    Try it Yourself »
    JavaScript
    // Setting Up Go
    console.log("=== Installing Go ===");
    console.log();
    console.log("Download from: https://go.dev/dl/");
    console.log();
    console.log("macOS:    brew install go");
    console.log("Ubuntu:   sudo apt install golang-go");
    console.log("Windows:  Download .msi installer from go.dev");
    console.log();
    
    console.log("=== Verify Installation ===");
    console.log("  $ go version");
    console.log("  go version go1.22.0 linux/amd64");
    console.log();
    
    console.log("=== Go Project Setup ===");
    console.lo
    ...

    3️⃣ Go Syntax Essentials

    Go has only 25 keywords — making it one of the simplest languages to learn. No semicolons, mandatory formatting, and unused imports/variables cause compile errors (keeping code clean by design).

    Try It: Syntax Basics

    Packages, imports, printing, and naming conventions

    Try it Yourself »
    JavaScript
    // Go Syntax Basics
    console.log("=== Go Syntax Overview ===");
    console.log();
    
    console.log("// Every Go file starts with a package declaration");
    console.log("package main");
    console.log();
    
    console.log("// Import single package:");
    console.log('import "fmt"');
    console.log();
    console.log("// Import multiple packages:");
    console.log("import (");
    console.log('    "fmt"');
    console.log('    "strings"');
    console.log('    "math"');
    console.log(")");
    console.log();
    
    console.log("=== Key Syntax Rules ==
    ...

    ⚠️ Common Mistakes

    ⚠️
    Opening brace on new line — Go requires func main() { on the same line. A newline brace causes a compile error.
    ⚠️
    Unused imports — Go won't compile with unused imports. Use _ as a blank identifier: import _ "fmt".
    💡
    Pro Tip: Use the Go Playground to experiment without installing anything.

    📋 Quick Reference — Go Basics

    ConceptGo Syntax
    Packagepackage main
    Importimport "fmt"
    Printfmt.Println("Hello")
    Rungo run main.go
    Buildgo build -o app
    Init modulego mod init name

    🎉 Lesson Complete!

    You now understand what Go is and can write your first program. Next, we'll dive into variables and Go's type system!

    Sign up for free to track which lessons you've completed and get learning reminders.

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy PolicyTerms of Service