ποΈ Introduction
1. History
ποΈ Data Types
In Go, data types define the type of value a variable can hold. Go has a rich set of built-in data types, and they can be categorized as basic types, composite types, pointer types, and interface types.
ποΈ Variables
In Go, variable declaration is straightforward but follows specific rules for type assignment and initialization
ποΈ Conditional Statements
In Go, conditional statements allow you to execute blocks of code based on certain conditions. The common conditional statements in Go are if, else, else if, and switch.
ποΈ Iterative Statements
In Go, Iterative statements allows you you repeat a set of instructions mutiple times, which is primarily achieved using for loop. Unlike many other programming languages, Golang only has one looping construct: for. It can be used in different forms to handle variety of iteration needs.
ποΈ Functions
A function is a block of code that performs a specific task. Itβs a reusable unit of code that can be called from other parts of your program. Functions help you organize your code, make it more modular, and improve readability.
ποΈ Packages
In Go, packages provide a way to organize and modularize code, making it easier to manage and reuse across different projects. The import and export rules in Go allow you to bring in external packages and control which parts of your package are accessible to other packages.
ποΈ Type Casting
In Go, type conversion, type inference, and type assertion are three distinct concepts. Hereβs a breakdown of each:
ποΈ Arrays & Slices
In Go, arrays and slices are two types of data structures used to store collections of elements. While they may look similar, they have key differences in usage, flexibility, and behavior.
ποΈ Maps
In Go map is built-in data structures that associate keys with values. maps are unordered collections of key-value pairs.
ποΈ Structs
In Go, Structs are a way to group the related data together into a single entity. They are similar to classes in other programming languages, but in Go does not have classes; instead, structs are used to define the complex types that can have multiple fields with different data types.
ποΈ Pointers
In Go, pointers are variable that hold the memory addresses of other variables. Using pointers , you can access and modify the values stored in the memory directly, allowing you to work efficiently with memory and optimize performance.
ποΈ Interfaces
In Go, interfaces define a set of method signatures (behavior) without specifying how these methods are implemented. A type implements an interface simply by defining all the methods declared by that interface, without needing explicit declaration. Interfaces allow for flexible and extensible code, making it easy to create functions that operate on any type that fulfills a specific contract.
ποΈ Go routines
In Go, goroutines are lightweight, independent threads of execution. They enable concurrent programming, allowing you to perform tasks simultaneously without blocking other operations.
ποΈ Channels
- In Go, channels are a core feature used for communication between goroutines, allowing them to synchronize by sending and receiving data. Channels are typed, meaning chan int can only carry int values. They act as conduits for data, enabling goroutines to pass information back and forth efficiently.
ποΈ Mutex
In Go, a mutex (mutual exclusion) is a synchronization primitive used to protect shared resources from being accessed concurrently by multiple goroutines. A mutex ensures that one go routine can access a critical section of code at a time, which is crucial for preventing race conditions when multiple goroutines are reading or modifying shared data.
ποΈ Defer
In Go, defer keyword is used to delay the execution of the function or statement until the surrounding function returns. defer is often used for resources cleanup, such as file closing, releasing locks, or disconnecting from database. Defered function are executed in Last in first out(LIFO) order, meaning the last defered function will run first.
ποΈ Panic & Recover
In Go, panic and recover are used for error handling in situations when an error is severe enough that program cannot continue as normal. They are typically used for handling unexpected or critical errors rather than routine error handling, which should use error values.
ποΈ Gnerics
Generics in Go, allow you to write functions and data structures that can operate on different types without sacrificing type safety. Generics make code more flexible and reusable by enabling you to define type parameters for functions, methods, and types.
ποΈ Buffer
In Go, buffer is a region of memory used to temporarily store data while it's being transfered between two places, such as between a file and memory or between a network connection and application. Buffers are particularly useful in scenarios where you need to build up or process data incrementally. Go provides buffering utilities, most notably in the bytes and bufio packages.
ποΈ Print Log Scan
ποΈ QnA
1. What is Golang?