0% found this document useful (0 votes)
4 views4 pages

Golang basics

Go, also known as Golang, is a compiled language created by Google in 2009, designed for speed, concurrency, and simplicity, making it ideal for backend services and high-performance applications. The document provides a quick start guide covering basic concepts such as variables, data types, functions, conditionals, loops, arrays, slices, maps, structs, and concurrency using goroutines. It emphasizes Go's clean syntax and unique features like goroutines for concurrent programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Golang basics

Go, also known as Golang, is a compiled language created by Google in 2009, designed for speed, concurrency, and simplicity, making it ideal for backend services and high-performance applications. The document provides a quick start guide covering basic concepts such as variables, data types, functions, conditionals, loops, arrays, slices, maps, structs, and concurrency using goroutines. It emphasizes Go's clean syntax and unique features like goroutines for concurrent programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Golang Basics

What Is Go (Golang)?

 Created by Google in 2009.

 Designed for speed, concurrency, and simplicity.

 Compiled language (like C/C++) but with a clean and readable


syntax (like Python).

 Great for backend services, cloud infrastructure, and high-


performance applications.

Go Basics: Quick Start Guide

1. Hello, World

package main

import "fmt"

func main() {

fmt.Println("Hello, World")

package main is the starting point of your Go program.

fmt.Println() prints output to the console.

2. Variables

var name string = "Rahul"

age := 25 // short declaration (Go infers type)

 Use var for explicit type.

 Use := for shorthand declaration (inside functions).

3. Data Types
 Basic: int, float64, string, bool

 Composite: array, slice, map, struct

 Special: interface, pointer, channel

4. Functions

func add(a int, b int) int {

return a + b

Functions start with func, then name, parameters, return type.

5. Conditionals

if age >= 18 {

fmt.Println("Adult")

} else {

fmt.Println("Minor")

No need for parentheses around conditions, but {} is mandatory.

6. Loops

for i := 0; i < 5; i++ {

fmt.Println(i)

Only for loop exists (acts as a while, foreach, etc.).


7. Arrays & Slices

arr := [3]int{1, 2, 3} // array

slice := []int{1, 2, 3, 4} // slice (dynamic size)

 Slices are more commonly used.

8. Maps (like dictionaries in Python)

person := map[string]string{

"name": "Rahul",

"city": "Delhi",

fmt.Println(person["name"])

9. Structs (like classes, but no inheritance)

type Person struct {

Name string

Age int

p := Person{Name: "Rahul", Age: 25}

10. Concurrency (Go’s Superpower)

go sayHello() // runs as a goroutine (like a lightweight thread)


Use go keyword to start concurrent functions (goroutines). Combine with
channels to sync.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy