Skip to content

Commit

Permalink
GitBook: No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrishguptaa authored and gitbook-bot committed Dec 26, 2023
1 parent 27a8442 commit 0d516bd
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/golang/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
---
description: Welcome to Krish's Golang Notes Library
---

# 🏠 Introduction

11 changes: 11 additions & 0 deletions src/golang/SUMMARY.md
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)
49 changes: 49 additions & 0 deletions src/golang/syntax/arrays.md
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)
22 changes: 22 additions & 0 deletions src/golang/syntax/functions.md
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 &#x26; 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
}
```
17 changes: 17 additions & 0 deletions src/golang/syntax/importing-other-files.md
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
```
44 changes: 44 additions & 0 deletions src/golang/syntax/types.md
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`
56 changes: 56 additions & 0 deletions src/golang/syntax/variables.md
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"
```

0 comments on commit 0d516bd

Please sign in to comment.