-
gci write --skip-generated -s standard -s default -s localmodule .
-
What does the . in a Go import statement do
- Allows functions inside the package to be called directly, but is not recommended
-
When should you use
errors.As
and when to useerrors.Is
for your own custom errorserrors.Is
forvar
errors,errors.As
for struct errors that has to be initialized (especially if it has custom fields)
-
How to test a unexported (private) function in go (golang)?, the article
-
7 Deadly Mistakes Beginner Go Developers Make (and how to fix them)
- You can label loops apparently
- map, slice, values in an interface are not addressable
- Pointer receivers can only accept pointers, while value receivers can accept both values and pointers
-
Golang struct configuration pattern
- Use a struct to pass optional values
- Allow the constructing function to take a list of functions that can modify the options to allow for extensibility
-
GopherCon 2016: Francesc Campoy - Understanding nil
- 16:30
- Use nil to disable channels
- Nil is valid as a read only empty map
-
The standard library now has all you need for advanced routing in Go
-
GothamGo 2018 - Things in Go I Never Use by Mat Ryer
- Lazy initialization (20:54)
sync.Once
: Guarantees thing inside code block will be called exactly once
- You can pass {the struct you want to work on} to {a method called on the struct using dot, ex.
Struct.method(actualObject)
}, don't do this but its interesting (22:20)
- Lazy initialization (20:54)
-
Golang UK Conference 2016 - Dave Cheney - SOLID Go Design
- Single Responsibility Principle
- Structure functions and types into packages that exhibit natural cohesion
- Avoid
shared
,utils
, which causes the packages to have multiple responsibilities
- Open / Closed Principle
- Open for extension, closed for modification
- Use embedding rather than inheritanca
- Liskov Substitution Principle
- Implicit interfaces, use small interfaces and express the dependencies between packages as interfaces
- Require no more, promise no less
- Interface Segregation Principle
- Clients should not be forced to depend on methods they don't use
- Ex. A
Save
function should only need aWriter
, instead ofRead
orFile
, or evenClose
, therefore it can work with network writer, file writers etc
- Dependency Inversion Principle
- High level modules should not depend on low level modules, both should depend on abstractions
- Abstractions should not depend on details. Details should depend on abstractions
- Import graph should be acyclic, push responsibility as high as possible in the import tree
- Single Responsibility Principle
-
Golang UK Conference 2016 - Mat Ryer - Idiomatic Go Tricks
- 9:16:
defer log.Println("------")
even if exits abnormally this code will print - defer can also be used for teardown functions for any setup / timers that need to stop at end of the line
- 21:18: Retry code
- 22:10: Empty structs to group methods methods don't capture the receiver, so the variable need not expose the private type
- 23:40: Semaphore code, limit hom many stuff is executed at once
- 9:16:
-
How To Build A Chat And Data Feed With WebSockets In Golang?
runtime.NumCPU
runtime.GOMAXPROCS()