Skip to content

Instantly share code, notes, and snippets.

@abdennour
Last active March 14, 2021 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdennour/e94470da30adc49053a853be6891bb97 to your computer and use it in GitHub Desktop.
Save abdennour/e94470da30adc49053a853be6891bb97 to your computer and use it in GitHub Desktop.
Golang Sheet Cheat

Value Types vs Reference Types

When using Value types, Use pointers to modify these things in a function

Value Types Reference Types
int slices
float maps
string channels
boot pointers
structs functions

Maps vs Structs

Maps Structs
All keys must be in the same type -
All values must be the same type Values can be of different types
Keys are indexed (can iterate over it) Keys don't support indexing
Use to represent a collection of related props Use to represent a "thing" with a lot of different props
Don't need to know all the keys at compile time Need to know all the different fields at compile time
Reference Type Value Type

Go Routines & Channel

The following snippets are the same :

 for s := range c {
     fmt.Println(s)
 }

 for {
     fmt.Println(<- c)
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment