/gotrain

Fundamentals training in Golang

Primary LanguageGo

gotrain

Fundamentals training in Golang

Main goal af this repo: Fundamentals training in Golang.

Daily devops tasks automation

  1. Parse csv dataset into predefined structs/maps:
go run parseCsv.go 
  1. Parse nginx access log from K8S pod as unformatted csv:
cd parsing-plain-text-example && go run parseNginx.go

topics:

  • get log as file from pod logs stdout
  • get rid of infra nginx logs and provide only clear access log using os for file ops and bufio Scanner to get rid of non-access log lines (using IP regex match)
  • parse as csv with whitespace delimeter
  • map it into struct with time.Time and int formats for response codes/timelogs

Unit testing

  1. Go to unit-test-example

  2. Run unit testing:

go test -v
  1. Check testing coverage:
go test -v -coverprofile=test-coverage.txt
  1. Prettify coverage profile in html:
go tool cover -html=test-coverage.txt -o test-coverage.html

Benchmark testing

  1. Go to sorting-example/merge-sort

  2. Run unit testing:

go test -bench=.

Sorting

Go to sorting-example/merge-sort, topics:

  • merge sort for customized struct objects
  • single thread sorting
  • multithread sorting (goroutine and waitgroups)
  • threads management (semaphore pattern as buffered channel for driving amount of goroutines and switch to single thread in case of limit exceeded)

Map Reduce operations

  1. Go to map-merge-reduce-example
  2. Run app:
go run mmr.go

topics:

  • get CSV data re: Covid cases from open sources
  • Define desired date to monitor cases in all countries (MAP training)
  • Define amount of critical deaths border (REDUCE training)
  • Sort values using merge sort alghoritm
  • MAP + multithread = creating struct objects from csv plain text
  • REDUCE + multithread = filter them by critical deaths border
  • Sort + multithread = sort by amount of death
  • Pretty print