Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Learning Go
- With Adrian
- https://github.com/solarwinds/golesson
- There’s only ONE way to format go.
- Go is simple:
- - Lowercase variables cannot be accessed via MAIN.
- - Uppercase is global.
- At branch: lesson2/0-http-handler, you can go to http://localhost:7777/hello and returns an http response.
- GO’s standard library is pretty damn good. Use their standard HTTP library.
- Small fact: since HTTP library is so good, lots of GO middleware just interfaces and plugs in and gets called by HTTP library. Any third party functions can just be called.
- Why do we write a function to return a function? Instead of just returning a function.
- - Go functions are closures?
- Branch: lesson2/2-channel-for-sigint
- “The hello world of channel usage”
- a channel is a conduit of sending values from one go routine to another go routine. You always have a MAIN go routine happening — but when u use the keyword ‘go’ anywhere, it starts ANOTHER routine.
- Channels are typed. U can only say one type of thing in that channel.
- GO’s concept is to not introduce radical new concepts — but to stay familiar.
- arrows mean something.<- is reading from. -> is coming into
- The arrows will block the channel until something is there to read. Can be bad.
- var sigIntChan = make(chan os.Signal, 1)
- signal.Notify(sigIntChan, os.Interrupt)
- go processSigInt()
- GO is not object oriented. does not thing objects are classes.thinks of types and interfaces.
- multiplexer (MUX)
- “I had a foobar type” go terminology.
- “MARSHAL” - like serializing. It turns struct into a json string. He said, u can write your own encoder but 99% of the time, Marshal will be more than enough bc go is very performant.
- Error is a built in interface. He says keep it simple, just turn a value and an error.
- This is beginner friendly error pattern:
- if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
- He really likes this. Forces you to handle every error. What if json doesn’t marshal?
- Json Marshall returns a slice of bytes. “Slice” is like an array.
- Should get into a habit of adding a ‘return’ just incase.
- TESTING
- Most people just use the standard Testing library. Go will recognize all functions that starts with the name Test.
- Go thing to do “cross compile a library”. When a library doesn’t work in one environment — he got into go when he was trying to cross compile python into C on a raspberry pi. Heard that Go can do it. Fell in <3.
- Theres only one loop in go. The for loop. With nothing in it, it is infinite. There are several flavors of for loop. 1. select.
- Using a Label busts u out of a for loop. *he mixes past this cuz its nbd. Just tell nurself, u got out of the loop!*
- Use GO for high speed applications
- Set up the things that READ before you set up the things that WRITE. Because server will hang forever if u mess up.
- Branch: lesson5/2-tuneable-stop-with-bug. go run main.go -friendly -time-limit=10 for crazy product managers who want something to exist for a limited duration.
- Bug is u must close the channel for the garbage collector. Will shut down whatever is trying to write to the channel.
- Branch: lesson5/3-tuneable-stop-fixed
- Added a variable called stopProcessing in web.go
- Flips a flag to return a 404
- Go - “black eye go” book. Cross compiling to make malware. Will give u a skeleton code for u to write malware with that will fit. Can interface with any OS.
- Port scanners/sniffers. CNC, network traffic.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement