-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27a8442
commit 0d516bd
Showing
7 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
--- | ||
description: Welcome to Krish's Golang Notes Library | ||
--- | ||
|
||
# 🏠 Introduction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Table of contents | ||
|
||
* [🏠 Introduction](README.md) | ||
|
||
## 🎼 Syntax | ||
|
||
* [🈁 Types](syntax/types.md) | ||
* [♒ Variables](syntax/variables.md) | ||
* [🦙 Functions](syntax/functions.md) | ||
* [📥 Importing Other Files](syntax/importing-other-files.md) | ||
* [🔄 Arrays](syntax/arrays.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
description: How to work with Arrays in Golang? | ||
--- | ||
|
||
# 🔄 Arrays | ||
|
||
{% hint style="info" %} | ||
Arrays start at index 0 | ||
{% endhint %} | ||
|
||
## Declaration | ||
|
||
```go | ||
var names [3]string | ||
|
||
names = ["Krish", "Kultiversan K", "K"] | ||
``` | ||
|
||
## Accessing | ||
|
||
```go | ||
names[0] // "Krish" | ||
``` | ||
|
||
## Assigning | ||
|
||
```go | ||
names[0] = "Karuto" | ||
``` | ||
|
||
## Appending | ||
|
||
```go | ||
names = append(names, "Hellooo") | ||
``` | ||
|
||
## Deleting | ||
|
||
```go | ||
names = append(names[:2], names[3:]...) | ||
``` | ||
|
||
## Tips | ||
|
||
> Tip: While defining variable, You can use `...` to let the compiler count the size for you | ||
> Note: While defining variable, if is not specified, it is unbounded | ||
> Note: When you use `arr[0:3]` you get the elements including index 0 to index 3, excluding index 3 (so 0, 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
description: Declaring functions in Golang | ||
--- | ||
|
||
# 🦙 Functions | ||
|
||
### One Return Variable | ||
|
||
<pre class="language-go"><code class="lang-go"><strong>// User & Format are argument types | ||
</strong><strong>func getName(user User, format Format) string { | ||
</strong> return user.getDetails(format).name | ||
} | ||
</code></pre> | ||
|
||
### Multiple Return Variable | ||
|
||
```go | ||
// User & Format are argument types | ||
func getNameAndAge(user User, format Format) (string, int) { | ||
return user.getDetails(format).name, user.getDetails(format).age | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
description: How to Import Files in Golang? | ||
--- | ||
|
||
# 📥 Importing Other Files | ||
|
||
{% hint style="warning" %} | ||
You can only import variables, functions, and types that start with a capital letter that are public and in the scope of the package | ||
{% endhint %} | ||
|
||
```go | ||
import "go-todo-api/types" // import package from module (module is the name in in go.mod) | ||
|
||
types.Name // You can access this | ||
|
||
types.name // You cannot access this as it does not start with capital letter | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
description: Built-in Types in Golang | ||
--- | ||
|
||
# 🈁 Types | ||
|
||
## Basics | ||
|
||
* `string` - "Hello, Gophers!" `%s` | ||
* `bool` - true | false `%t` | ||
|
||
## Numbers | ||
|
||
### Integers | ||
|
||
* `int` - -2147483648 to 2147483647 `%d` | ||
* `int8` - -128 to 127 `%d` | ||
* `int16` - -32768 to 32767 `%d` | ||
* `int32` - -2147483648 to 2147483647 `%d` | ||
* `int64` - -9223372036854775808 to 9223372036854775807 `%d` | ||
|
||
### Unsigned Integers | ||
|
||
{% hint style="info" %} | ||
Unsigned integers are integers that are only positives. | ||
{% endhint %} | ||
|
||
* `uint` - 0 to 4294967295 `%d` | ||
* `uint8` - 0 to 255 `%d` | ||
* `uint16` - 0 to 65535 `%d` | ||
* `uint32` - 0 to 4294967295 `%d` | ||
* `uint64` - 0 to 18446744073709551615 `%d` | ||
|
||
### Float (Decimals) | ||
|
||
* `float32` - IEEE-754 32-bit floating-point numbers `%f` | ||
* `float64` - IEEE-754 64-bit floating-point numbers `%f` | ||
* `complex64` - complex numbers with float32 real and imaginary parts `%f` | ||
* `complex128` - complex numbers with float64 real and imaginary parts `%f` | ||
|
||
## Alias | ||
|
||
* `byte` - alias for `uint8` | ||
* `rune` - alias for `int32` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
description: How to declare variables? | ||
--- | ||
|
||
# ♒ Variables | ||
|
||
## Types | ||
|
||
### Based on mutability: | ||
|
||
* Immutable (constants) - Cannot be changed | ||
* Mutable (vars) - Can be changed | ||
|
||
## Examples | ||
|
||
### Vars | ||
|
||
#### Without Assignment | ||
|
||
```go | ||
// declaration | ||
var name string | ||
|
||
// later in the code | ||
name = "Krish Gupta" | ||
``` | ||
|
||
#### With Assignment | ||
|
||
```go | ||
var name string = "Krish Gupta" | ||
``` | ||
|
||
#### Inferred | ||
|
||
```go | ||
// one | ||
name := "Krish Gupta" | ||
|
||
// more than one | ||
name, age := "Krish Gupta", 18 | ||
``` | ||
|
||
### Constants | ||
|
||
#### Explicit Type | ||
|
||
```go | ||
const name string = "Krish Gupta" | ||
``` | ||
|
||
#### Inferred Type | ||
|
||
```go | ||
const name = "Krish Gupta" | ||
``` |