Skip to content
T2Run
Esc
  • RunPad Text Editor
    A Notepad++-style editor in your browser: tabs, split view, compare, 30 languages, JSON/XML/YAML tools.
    Text
  • Diff Checker
    Compare two texts or files side by side and see every added, removed and changed line.
    Text
  • JSON Beautifier
    Format, validate, sort and minify JSON with precise error locations.
    JSON & Data
  • Image Resizer
    Batch resize photos by pixels or percent and export to JPG, PNG or WebP.
    Image
  • JSON Validator
    Check if JSON is valid and see the exact line and column of any error.
    JSON & Data
  • JSON Minifier
    Remove whitespace to make JSON compact, and see how many bytes you saved.
    JSON & Data
  • JSON to Go Struct
    Generate Go struct type definitions with json tags from any JSON.
    JSON & Data
  • JSON to String
    Escape JSON into a string literal you can paste into code.
    JSON & Data

GO TUTORIAL

Learn Go, one practical step at a time

Go is a simple, fast language built at Google for cloud services, CLIs and concurrent programs. Start with the articles below, then try the example program.

Start here

Golang Basics

run a simple Hello world Go Program Online.

· 1 min read

Example: Armstrong numbers

A number is an Armstrong number when the sum of the cubes of its digits equals the number itself — for example153 = 1³ + 5³ + 3³. This program reads a number, peels off each digit with% 10 and / 10, and checks the sum.

Try it in the Go Playground.

// Check whether a number is an Armstrong number.
// A positive integer is an Armstrong number of order n if the sum of
// the nth powers of its digits equals the number: 153 = 1³ + 5³ + 3³.
package main

import "fmt"

func main() {
    var number int
    fmt.Print("Enter any three digit number: ")
    fmt.Scan(&number)
    checkArmstrongNumber(number)
}

func checkArmstrongNumber(number int) {
    var remainder, result int
    tempNumber := number

    for tempNumber != 0 {
        remainder = tempNumber % 10            // last digit, e.g. 3 for 153
        result += remainder * remainder * remainder
        tempNumber /= 10                      // drop the last digit
    }

    if result == number {
        fmt.Printf("Number %d is an Armstrong number.\n", number)
    } else {
        fmt.Printf("Number %d is not an Armstrong number.\n", number)
    }
}

// $ go run check_armstrong.go
// Enter any three digit number: 153
// Number 153 is an Armstrong number.

Coming next

Topics planned for this tutorial.

  1. 1Program structureNames, declarations, variables, assignments, packages and scope
  2. 2Data typesIntegers, floats, complex numbers, strings, booleans and constants
  3. 3Composite typesArrays, slices, maps, structs and JSON
  4. 4FunctionsVariadic functions, closures, recursion, multiple returns, errors, defer, panic & recover
  5. 5MethodsMethods on types and pointer receivers
  6. 6InterfacesImplicit interfaces, type assertions and type switches
  7. 7Standard libraryThe packages you will use every day
  8. 8Goroutines & channelsLightweight concurrency
  9. 9Concurrency patternsWorker pools, pipelines, fan-in/fan-out, select
  10. 10ReflectionInspecting types at runtime
  11. 11TestingUnit tests, table-driven tests and benchmarks
  12. 12Interview questionsCommon Go interview topics