Tsallaka zuwa abun ciki
Justice Tech School

Go Tutorial

A simple, fast language built for servers and concurrency.

Start learning Go
Getting started3 lessons
  1. 1Go IntroductionSimple, fast and built for servers.
  2. 2Go Get StartedInstall Go and run a file.
  3. 3Go Syntax and CommentsPackages, imports and comments.
Basics25 lessons
  1. 4Variables and Typesvar, := and basic types.
  2. 5If, For and SwitchGo has one loop: for.
  3. 6Declare Variablesvar and := in detail.
  4. 7Variable Naming RulesValid names and exported names.
  5. 8ConstantsValues that never change.
  6. 9Go OutputPrint, Println and Printf.
  7. 10Declare Multiple VariablesDeclare several variables in one line with commas or a var block.
  8. 11Zero Values and newVariables without a value get a zero value: 0, an empty string, false or nil.
  9. 12VariablesDeclare with var or the short form :=.
  10. 13Constants and iotaconst holds fixed values.
  11. 14Basic Typesint, int64, uint8, float64, string, bool, byte and rune.
  12. 15Type ConversionGo never converts types implicitly.
  13. 16Printf FormattingVerbs: %v any value, %d int, %s string, %f float, %q quoted, %T type, %5.2f width and prec.
  14. 17Println, Sprintf and ErrorfPrintln adds spaces and newline, Sprintf returns a string and Errorf builds errors.
  15. 18Reading Inputfmt.Scan and bufio.Scanner read input.
  16. 19Arithmetic and Operators+ - * / % and bit operators.
  17. 20The math Packagemath has Sqrt, Pow, Abs, Floor, Ceil, Max, Min, Pi and more.
  18. 21The strings Packagestrings has Contains, Split, Join, Replace, ToUpper, TrimSpace, HasPrefix and more.
  19. 22Strings, Bytes and RunesStrings are UTF-8 bytes.
  20. 23Booleans and Logicbool holds true or false.
  21. 24Scope and ShadowingVariables live in their block.
  22. 25Comparing ValuesArrays and structs are comparable with ==.
  23. 26min, max and clearGo 1.21 added the builtins min, max and clear.
  24. 27The slices Packageslices has Sort, Contains, Index, Reverse, Max and more for any slice.
  25. 28The maps Packagemaps.Keys and maps.Values return iterators and maps.Clone copies a map.
Data types6 lessons
  1. 29Data TypesThe basic types.
  2. 30StringsText and the strings package.
  3. 31Numbers and strconvParsing and converting.
  4. 32Booleans, Integers and FloatsInteger sizes are int8 to int64 and uint8 to uint64, plus int and uint.
  5. 33Runes, Bytes and UnicodeA string is a read only sequence of bytes.
  6. 34Custom Typestype Celsius float64 creates a new type with its own methods.
Operators3 lessons
  1. 35OperatorsArithmetic, comparison and logic.
  2. 36Bitwise OperatorsOperators & | ^ &^ << >> work on bits, and &^ clears bits.
  3. 37Comparison and Logical OperatorsComparison operators are == != < > <= >=.
Control flow12 lessons
  1. 38If, Else If and Nested IfConditions in detail.
  2. 39SwitchSingle and multi case.
  3. 40For LoopsCounting, conditions and range.
  4. 41Labels, break and continueA label names a loop so break and continue can target an outer loop from inside a nested o.
  5. 42Type Switch and fallthroughA type switch checks the dynamic type held by an interface.
  6. 43if and elseNo parentheses, braces required.
  7. 44for Is the Only Loopfor has three parts, a while form and an infinite form.
  8. 45rangerange gives index and value for slices, keys and values for maps and runes for strings.
  9. 46switchswitch does not fall through by default.
  10. 47break, continue and Labelsbreak leaves, continue skips and labels target outer loops.
  11. 48deferdefer runs a call when the function returns, in last in first out order.
  12. 49Simple Programs: Sum and FactorialCombine loops and functions to solve small problems.
Data23 lessons
  1. 50Arrays, Slices and MapsCollections.
  2. 51Structs and MethodsCustom types.
  3. 52ArraysFixed size lists.
  4. 53SlicesFlexible views.
  5. 54MapsKey value data.
  6. 55Slices In DepthRemove and insert with append and re-slicing.
  7. 56Maps In DepthWriting to a nil map panics, so create it with make.
  8. 57Sortingsort.Ints and sort.Strings sort basic slices.
  9. 58strings.Builder and Helpersstrings.Builder builds text efficiently.
  10. 59ArraysAn array has a fixed length that is part of its type.
  11. 60SlicesSlices are flexible views of arrays.
  12. 61make and Capacitymake creates slices and maps with a length and capacity.
  13. 62copy and SharingSlices share memory.
  14. 63Slices of SlicesA slice of slices builds a grid.
  15. 64MapsMaps store key value pairs.
  16. 65Iterating Maps in OrderMap order is random.
  17. 66StructsA struct groups fields.
  18. 67Pointers& takes an address and * reads through a pointer.
  19. 68MethodsA method is a function with a receiver.
  20. 69Struct EmbeddingEmbed a struct to reuse its fields and methods.
  21. 70InterfacesAn interface lists methods.
  22. 71Type Assertions and SwitchesCheck the dynamic type of an interface value with .(T) or a type switch.
  23. 72GenericsType parameters let one function work for many types.
Functions and errors27 lessons
  1. 73FunctionsMultiple returns.
  2. 74ErrorsReturn and check errors.
  3. 75InterfacesBehaviour by shape.
  4. 76Parameters, Returns and RecursionMore on functions.
  5. 77Defer, Panic and RecoverClean up and last resorts.
  6. 78Closures and Function ValuesFunctions are values.
  7. 79Variadic Functions and Method ValuesA variadic parameter collects extra arguments into a slice.
  8. 80Packages, init and ImportsEvery file belongs to a package.
  9. 81Errors In PracticeReturn errors, add context with fmt.Errorf and %w, and handle them once at the right level.
  10. 82Functionsfunc name(params) result.
  11. 83Named ReturnsName the results to document them.
  12. 84Variadic FunctionsUse ...T to accept any number of arguments as a slice.
  13. 85Function Values and ClosuresFunctions are values.
  14. 86ErrorsFunctions return an error as the last value.
  15. 87Custom Errors and Wrappingerrors.New makes an error and %w wraps one.
  16. 88panic and recoverpanic stops normal flow.
  17. 89Packages, main and initEvery program starts in package main.
  18. 90Testing BasicsTests live in _test.go files and use the testing package.
  19. 91The time Packagetime has Duration, Now, Since and formatting with a reference layout.
  20. 92JSONencoding/json Marshal and Unmarshal convert structs and JSON.
  21. 93Files with osos.WriteFile and os.ReadFile handle small files quickly.
  22. 94bufio Scannerbufio.Scanner reads line by line from any reader.
  23. 95The sort Packagesort.Ints, sort.Strings and sort.Slice order data.
  24. 96strings.BuilderBuilder joins many pieces efficiently.
  25. 97Practice: Word CountCount words with a map.
  26. 98Practice: FibonacciGenerate numbers with a loop and multiple assignment.
  27. 99Practice: Reverse and PalindromeReverse runes to support Unicode.
ConcurrencyPremium2 lessons
  1. 100Goroutines and ChannelsConcurrency made simple.
  2. 101Buffered Channels and rangeA buffered channel holds values without a receiver.
Advanced GoPremium11 lessons
  1. 102PointersAddresses and shared values.
  2. 103Struct Tags, Embedding and CompositionReuse without inheritance.
  3. 104GenericsType parameters (Go 1.18+).
  4. 105Custom Errors and Wrappingerrors.Is and errors.As.
  5. 106WaitGroups and MutexesCoordinating goroutines.
  6. 107Select, Timeouts and Worker PoolsPatterns for real programs.
  7. 108Context and Cancellationcontext carries deadlines, cancellation signals and request values across goroutines and A.
  8. 109JSON with encoding/jsonMarshal turns values into JSON and Unmarshal reads it back.
  9. 110Files and ioos.ReadFile and os.WriteFile handle whole files.
  10. 111Embedding Interfaces and Method SetsInterfaces can embed other interfaces.
  11. 112sync/atomic, Once and sync.Poolatomic counters avoid locks for simple values.
Go in practicePremium8 lessons
  1. 113Testing with go testTable driven tests.
  2. 114Building an HTTP Servernet/http basics.
  3. 115Benchmarks and ProfilingBenchmark functions start with Benchmark and loop b.N times.
  4. 116Modules and Toolinggo mod tidy cleans dependencies, go get adds one, go vet finds suspicious code, gofmt form.
  5. 117Databases with database/sqldatabase/sql provides a generic interface to databases.
  6. 118REST APIs with net/http and FrameworksSince Go 1.22 the standard mux supports methods and path parameters.
  7. 119Docker and DeploymentGo builds one static binary, so a tiny Docker image works.
  8. 120Go Best PracticesAccept interfaces and return structs, handle every error, keep packages small, prefer comp.
Next steps1 lessons
  1. 121What Next?Where to go after the basics.