ProgramGuru

Introduction to Go Programming

Start with Introduction to Go Programming

Go is a compiled, statically typed programming language designed for building reliable software with straightforward code. You can start with tiny command-line programs and later use the same language for web servers, networking tools and concurrent applications.

What you’ll learn

  • Identify Go source files and executable programs.
  • Explain the role of package main and the main function.
  • Run and modify a small Go example.

Understand the idea

Go is often called Golang in searches, but its language name is Go. You write source code in .go files; the Go toolchain checks and compiles that code before the program executes.

To begin, distinguish source code (the instructions you edit), the compiler (which translates those instructions), and the program (which runs). You do not need to learn deployment or concurrency yet.

Visualize how it works

Follow this diagram before executing the example. Check where a value or decision changes what runs next.

Visual explanation for introductionA source file is checked and compiled; its instructions then produce a visible result.Go source codeStep 1Go compilerStep 2Executable programStep 3OutputStep 4A source file is checked and compiled; its instructions then produce a visible result.
A source file is checked and compiled; its instructions then produce a visible result.

Tools, syntax and practical notes

Start at the official Go website. This course progresses from writing values and branches to organizing real applications.

Run a complete Go example

This example is a complete program. Save it as main.go or paste it into the Go Playground.

Go code

package main

import "fmt"

func main() {
	fmt.Println("Learning Go begins here")
}

Output

Learning Go begins here

Trace what the program does

The main package marks an executable program. Execution enters main(), which calls fmt.Println to print one line. The quotation marks delimit the string in source code; they are not part of the printed text.

Avoid common mistakes

  • Go source files normally end in .go, not .golang.
  • The name main has a special role only when used as the package and entry-point function of an executable.

Try it yourself

Change the greeting to your name and print a second sentence. Predict the two output lines before running.

Tip: Edit the example above, predict the output, and run the modified code to test your reasoning.

Check your understanding

Which function does a simple executable Go program enter when it starts?
Choose one answer. You can try again.

Answer and explanation

main() in package main

Correct. The main package marks an executable program.

What you should remember

You have practiced Introduction to Go Programming in a small, self-contained program. The important habit is to predict what runs, inspect the actual output and distinguish the language rule from the particular example.

Before continuing, make sure you can explain the program to someone who has not seen it, including the line that changes its result.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Features of Go →