Skip to content

Commit e34a2c7

Browse files
author
arvryna
committed
Add notes: GC, Interface, Error
1 parent 1fd08b5 commit e34a2c7

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

Diff for: README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func(s string){fmt.print(s)}("Hello")
3838
NOTE: capturing the state means that, the closure will somehow associate that specific closure with the variables passed to it. In the above example, this specific instance of a function is linked with the variable passed to it. It becomes particularly important when enclosing closures in loops. So each instance of closure will be given a unique reference to variable s.
3939

4040
# Pointers
41+
- Share memory by pointer
4142
- Map by default is reference in go
4243
- Passing pointer by reference example
4344

@@ -80,6 +81,13 @@ fetch(&data)
8081
- If all goroutines are deadlocked, go raises panic to kill program, but if there is partial failure of go-routines, the program
8182
continues to function but may behave uncertain.
8283

84+
# Interface:
85+
- They define behaviour of an Object, by expecting presence of certain methods.
86+
- This helps us to implement OOP in go.
87+
- passing interface as parameter provides a clean way to generalize and allow us to pass different kinds of
88+
objects
89+
- See example here: https://github.com/arvryna/sled/blob/main/internal/service/task.go
90+
8391
# Go Tools:
8492
> Detecting race conditions ?
8593
- Use race flag to detect race conditions in the program
@@ -100,6 +108,11 @@ signal.Notify(sigListen, syscall.SIGINT, syscall.SIGTERM)
100108
// Add code for graceful shutdown here
101109
```
102110

111+
# Interceptors
112+
Block of code that you want to execute before it executes a handler of web request for example. This works similar
113+
to constuct like before_action, after_action in rails for example.
114+
115+
103116
# Working with docker
104117
An example of a simple hw app with a dockerfile can be found here `samples/greeter`
105118

@@ -112,6 +125,3 @@ An example of a simple hw app with a dockerfile can be found here `samples/greet
112125
- [Google go's guide](https://github.com/golang/go/wiki/CodeReviewComments)
113126
- [Effective go](https://go.dev/doc/effective_go)
114127
- [Kubernets go coding convention](https://www.kubernetes.dev/docs/guide/coding-convention/)
115-
116-
# Best practices:
117-
- Use defer whenever possible

Diff for: advanced/garbage-collection.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# Source code of Go's garbage collection here:
3+
https://github.com/golang/go/blob/master/src/runtime/mgc.go
4+
5+
# Basics:
6+
- stack allocations are cleaned by themselves eg, function calls and its local vars (no need for GC)

Diff for: best-practices.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Best practices:
3+
- Use defer whenever possible
4+
5+
# Errors:
6+
- Export/Return error as variable, it helps you to compare error easily, instead of comparing strings.
7+
- Another way is to create a custom type to encapsulate message and defining error codes.

Diff for: go-dep.md renamed to dependencies.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
- can read config from remote systems like etcd, or consul
88
- it can watch for config file changes and also notify the go-process
99
- you can marshal/unmarshal using mapstructure
10-
- `go get github.com/spf13/viper`
10+
- `go get github.com/spf13/viper`
11+
12+
# ORM
13+
- gorm is a popular ORM
14+
- to connect with postgres, driver is required additionally

Diff for: r.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
3+
go run main.go

0 commit comments

Comments
 (0)