diff --git a/languages/golang.md b/languages/golang.md index fa6d370..7cd35c7 100644 --- a/languages/golang.md +++ b/languages/golang.md @@ -2,32 +2,37 @@ ## Summary -- Introduction - - [Hello World](#hello-world) - - [Go CLI Commands](#go-cli-commands) - - [Go Modules](#go-modules) -- Basic - - [Basic Types](#basic-types) - - [Variables](#variables) - - [Operators](#operators) - - [Conditional Statements](#conditional-statements) - - [Loops](#loops) - - [Arrays](#arrays) - - [Functions](#functions) -- Advanced - - [Structs](#structs) - - [Maps](#maps) - - [Pointers](#pointers) +- Introduction + - [Hello World](#hello-world) + - [Go CLI Commands](#go-cli-commands) + - [Go Modules](#go-modules) +- Basic + - [Basic Types](#basic-types) + - [Variables](#variables) + - [Operators](#operators) + - [Conditional Statements](#conditional-statements) + - [Loops](#loops) + - [Arrays](#arrays) + - [Functions](#functions) +- Advanced + - [Structs](#structs) + - [Maps](#maps) + - [Pointers](#pointers) + - [Methods and Interfaces](#methods-and-interfaces) + - [Errors](#errors) + - [Testing](#testing) +- Standard Libs + - [Package fmt](#package-fmt) ## Hello World ```go -package main +package main import "fmt" func main() { - fmt.Println("Hello World!") + fmt.Println("Hello Gophers!") } ``` @@ -44,7 +49,7 @@ $ go run [file.go] # Compile $ go build [file.go] # Running compiled file -$ ./hello +$ ./hello # Test packages $ go test [folder] @@ -80,16 +85,17 @@ $ go version ## Go Modules -- Go projects are called **modules** -- Each module has multiple **packages** -- Each package should has a scoped functionality. Packages talk to each other to compose the code -- A module needs at least one package, the **main** -- The package main needs a entry function called **main** +- Go projects are called **modules** +- Each module has multiple **packages** +- Each package should has a scoped functionality. Packages talk to each other to compose the code +- A module needs at least one package, the **main** +- The package main needs a entry function called **main** ```bash # Create Module -$ go mod init [name] +$ go mod init [name] ``` + Tip: By convention, modules names has the follow structure: domain.com/user/module/package @@ -102,25 +108,25 @@ Example: github.com/spf13/cobra ## Basic Types -| Type | Set of Values | Values | -|:---------:|:-----------------:|:---------:| -| bool | boolean | true/false | -| string | array of characters | needs to be inside "" | -| int | integers | 32 or 64 bit integer | -| int8 | 8-bit integers | [ -128, 128 ] | -| int16 | 16-bit integers | [ -32768, 32767] | -| int32 | 32-bit integers | [ -2147483648, 2147483647] | -| int64 | 64-bit integers | [ -9223372036854775808, 9223372036854775807 ] | -| uint8 | 8-bit unsigned integers | [ 0, 255 ] | -| uint16 | 16-bit unsigned integers | [ 0, 65535 ] | -| uint32 | 32-bit unsigned integers | [ 0, 4294967295 ] | -| uint64 | 64-bit unsigned integers | [ 0, 18446744073709551615 ] | -| float32 | 32-bit float | | -| float64 | 64-bit float | | -| complex64 | 32-bit float with real and imaginary parts | | -| complex128 | 64-bit float with real and imaginary parts | | -| byte | sets of bits | alias for uint8 | -| rune | Unicode characters | alias for int32 | +| Type | Set of Values | Values | +| :--------: | :----------------------------------------: | :-------------------------------------------: | +| bool | boolean | true/false | +| string | array of characters | needs to be inside "" | +| int | integers | 32 or 64 bit integer | +| int8 | 8-bit integers | [ -128, 128 ] | +| int16 | 16-bit integers | [ -32768, 32767] | +| int32 | 32-bit integers | [ -2147483648, 2147483647] | +| int64 | 64-bit integers | [ -9223372036854775808, 9223372036854775807 ] | +| uint8 | 8-bit unsigned integers | [ 0, 255 ] | +| uint16 | 16-bit unsigned integers | [ 0, 65535 ] | +| uint32 | 32-bit unsigned integers | [ 0, 4294967295 ] | +| uint64 | 64-bit unsigned integers | [ 0, 18446744073709551615 ] | +| float32 | 32-bit float | | +| float64 | 64-bit float | | +| complex64 | 32-bit float with real and imaginary parts | | +| complex128 | 64-bit float with real and imaginary parts | | +| byte | sets of bits | alias for uint8 | +| rune | Unicode characters | alias for int32 | [Return to Summary](#summary) @@ -130,7 +136,7 @@ Example: github.com/spf13/cobra ```go // Declaration -var int value +var int value // Initialization value = 10 @@ -171,7 +177,7 @@ const pi = 3.1415 [Return to Summary](#summary) Arithmetic Operators -| Symbol | Operation | Valid Types | +| Symbol | Operation | Valid Types | |:---------:|:-------------:|:-------------:| | `+` | Sum | integers, floats, complex values, strings | | `-` | Difference | integers, floats, complex values | @@ -186,7 +192,7 @@ Arithmetic Operators | `>>` | Right shift | integer >> unsigned integer | Comparison Operators -| Symbol | Operation | +| Symbol | Operation | |:---------:|:-------------:| | `==` | Equal | | `!=` | Not equal | @@ -196,7 +202,7 @@ Comparison Operators | `>=` | Greater or equal | Logical Operators -| Symbol | Operation | +| Symbol | Operation | |:---------:|:-------------:| | `&&` | Conditional AND | | `||` | Conditional OR | @@ -250,7 +256,7 @@ switch text { // 'Byee' default: // 'Ok' -} +} // Switch without condition value := 5 @@ -262,7 +268,7 @@ switch { // 'Byee' default: // 'Ok' -} +} ``` [Return to Summary](#summary) @@ -295,7 +301,7 @@ for {