private-schrijfsels-en-noti.../2023/golang-talk-han-jan-23/workshop-brainstorm-notes.m...

2.8 KiB

Workshop golang HAN ESE jan '23

Tekst wat de workshop inhoud:

  • Wat ga ik doen
  • Verwachting als ze geweest zijn
  • Wat moeten ze meenemen

Workshop inhoud:

"Writing a tcp server for embedded devices in Golang within hours"

Course time schedule (50 min)

- 10 min: About myself, the company I work for and Golang introduction
- 5 min: Exercise explanation
- 30 min: Golang hands-on with support from me (2 persons per exercise)
- 5 min: The outcome and questions

Bring a laptop with a browser and wifi. The Google Chrome browser is preferred. 

Slides

Interesting packages

  • buffer
  • net
  • io

Golang online playground

Functional Options Pattern in Golang

https://michalzalecki.com/golang-options-pattern/ https://petomalina.medium.com/dealing-with-optional-parameters-in-go-9780f9bfbd1d https://www.sohamkamani.com/golang/options-pattern/

Normaly you would fill in many parameters or pass a struct with many knobs to turn. The Optional Function Parameter Pattern in Golang deals in a unique way with module parameters which can be added and removed without extending the type with extra setter and getter functions. As options is a type they can be passed in as a slice.

Excercise

The net package

For cross platform TCP/UDP/UNIX network socket access. From the builtin net package.

The show must go on ...

Good Golang content to keep the ball rolling

Opdracht

  • Zorg dat het programma na 16 client handlings afsluit als alle processing klaar is

TODO & Braindump

  • Programming Golang since 2016
  • Zet oefening met sharelink op https://goplay.tools/snippet/XOM0c7Dp0YD
  • Running opensource project Syncthing macOS
  • Check if firefox also works with https://go.dev/play/
  • Golang uses composition for OO-like system instead of polymorphism which is easier to read and write
  • GOlang has an interface type builtin to the language (e.g io.Reader)
  • cmd package is special where executables are
  • Multiple return values
  • Variables are ALWAYS initialised (for safety)
  • Slices to keep things together (len, cap, size)
  • Public/private no keyword but by contract (highercase is public, lowercase private)