TOC: Golang
- Introduction to Golang
- Features
- Why Golang?
- Go Designed by
- Open Souce
- Platforms
- Major Open Source Projects
- Install Golang
- Show Installed Version of Golang
- Editor/IDE for Golang
- Hello World
- Build Hello World exe
- Source of examples
- Separate directories! - main redeclared in this block
- Exercise: Hello World
- Basics
- Hello Foo - Println
- Hello Bar - Printf
- Hello Bar - Printf %v
- Enforce variables types
- Basic Types
- Show inferred variable type - Printf %T
- Show type of variable - reflect.TypeOf
- get variable type - %T or reflect.TypeOf
- Variable declaration (var)
- Default values of variables
- Scan input strings from STDIN
- if else statement
- Converting string to integer - strconv, Atoi
- Error Handling
- Converting string to integer with error handling - strconv, Itoa
- Converting string to float - strconv, ParseFloat
- Converting integer to string - strconv, Itoa
- Scan STDIN convert to number
- Comments
- Exercise: circle STDIN
- Exercise: rectangular STDIN
- Exercise: calculator STDIN
- Solution: circle STDIN
- Solution: circle STDIN with math
- Solution: rectangular STDIN
- Solution: calculator STDIN
- Solution: calculator STDIN switch
- CLI
- Args - (argv) command line arguments
- Exit early with exit code
- Exercise: rectangular
- Exercise: calculator
- Solution: rectangular CLI
- TODO: Solution: calculator CLI
- TODO: Solution: calculator (switch)
- Skeleton
- empty file
- Only package main
- Other package name
- Skeleton file
- Numbers
- Integer-based operations
- Floating-point based operations
- Precision
- Mixed operations
- int8
- uint8
- Bytes
- Byte is uint8
- uint16
- uint32
- Converting values to other types - float32, int, string
- Complex numbers
- binary - octal - hex
- Random
- Random with seed
- Exercise: One-dimensional spacefight - level 1
- Solution: One-dimensiona spacefight - level 1
- Boolean - Logical operators
- Boolean values - bool, true, false
- Boolean truth table
- Loops
- 3-part for loop
- while-like for loop
- infinite loop
- break out from loop
- continue
- loop on two variables
- break out from internal loop (labels)
- Exercise: One-dimensional spacefight
- Exercise: FizzBuzz
- Solution: One-dimensional spacefight - multiple guesses till hit
- Solution: One-dimensional spacefight - allow x
- Solution: One-dimensional spacefight - allow m
- Solution: FizzBuzz
- Strings
- Single and double quotes
- Runes
- Strings
- Change string
- Strings and Runes
- Length of string
- iterate over characters in a string
- String Contains, HasPrefix, HasSuffix
- Split
- Join
- Split on whitespaces
- Newlines
- Read line from stdin (keyboard)
- Read line from stdin (keyboard) with error handling
- Trim line - remove trailing newline from string
- Strings and bytes
- Scan in a loop
- Compare strings
- Raw strings
- Multiline strings
- Exercise: how long is this string?
- Exercise: which string is longer?
- Exercise: which string is ahead in ABC?
- Exercise: which string is ahead - menu
- Exercise: Hide substring
- Solution: how long is this string?
- Solution: which string is longer?
- Solution: which string is ahead in ABC?
- Solution: which string is ahead - menu
- Solution: Hide substring
- Arrays
- Arrays
- Array index out of range - compile time
- Array index out of range - run time
- Array change value
- Arrays automatic length
- Array: empty and fill
- Empty array of strings
- Array assignment (copy)
- Array assignment (pointer)
- Matrix (two dimensional array)
- For loop on array - iterate over array
- for loop on values of array (no index)
- Arrays conclusion
- Exercise: Language Selector
- Exercise: count digits
- Exercise: count digits from string
- Exercise: Report statistics
- Solution: Language Selector
- Solution: count digits
- Solution: count digits from string
- Solution: Report statistics
- Variables
- Variable Declarations
- Variables - Naming
- Declare multiple variables in one line
- Variables cannot be redefined (no new variables on left side of :=)
- At least one new variable on the left side of :=
- Use the same err on the left hand side
- Package variable
- Shadowing package variable
- Variable scope
- Constants
- Constants
- Constants cannot be changed
- Shadowing constants
- Constant blocks
- iota
- iota skipping 0
- const powers of 2
- Functions
- Hello World function
- Hello You function (passing parameter)
- Function with multiple parameters
- Function with return value
- Multiple return values
- Returning an error from a functions
- Named return parameters
- Passing a function as a parameter - Callback function
- Callback function with one parameter
- Anonymous functions
- Anonymous functions assigned to name
- Numbers are passed by value
- Function Overloading - Multiple function with the same name
- Defer
- Defer early returns
- Deferred cd in a function
- Defer in if-statements
- Defer and parameters
- Exercise: Fibonacci
- Exercise: Defer remove temporary directory
- Exercise: FizzBuzz in function
- Exercise: ROT13
- Solution: FizzBuzz in function
- Solution: ROT13
- Slices
- Slice of an array
- Slice
- Change value in slice
- Slice Assign
- Slice of a slice
- Append to a slice
- Slice append
- Remove last element of slice (pop)
- Remove first element of slice (shift, pop(0))
- Pre-allocate capacity for slice with make
- For loop in slice - iterate over slice
- for loop on values of slice (no index)
- Merge two slices
- Find element in array or slice
- Remove element of slice
- Weird merge slices
- Sort slice
- Are values sorted?
- Sort strings by length
- Sort strings by length and then abc order
- Search in slice
- Variadic function (arbitrary number of parameters)
- Defer and slice
- Exercise: count words
- Exercise: Create a list of words from sentences
- Exercise: Create a unique list of values
- Exercise: Reverse Polish Calculator
- Exercise: DNA Sequencing
- Solution: count words
- Solution: Create a list of words from sentences
- Solution: Create a unique list of values
- Solution: Reverse Polish Calculator
- Solution: DNA Sequencing
- Solution: DNA Sequencing with in place filter
- Files
- Read file line-by-line with Scanner
- Read file line by line with Reader
- Read file as one string (slurp)
- Write to file
- Write number to file
- Append to file
- Reading CSV file
- Exercise: Sum of numbers in a file
- Exercise: Count number of digitis
- Exercise: ROT13 on file
- Exercise: Selector with list of items from a file
- TODO: Solution: Sum of numbers in a file
- Maps
- Map (hash, dictionary)
- Empty Map
- Empty Map with make
- Map type defintion without container
- Create map with data in it already
- Delete Map element
- Size of map (len)
- Access map element (that does not exist)
- Map element exists
- Increment map elements
- Iterate over elements of map
- Keys of a map
- Sort map
- Sort map by value
- map of slices
- Mixed map
- Exercise: count characters
- Exercise: count characters - sort by frequency
- Exercise: count words
- Exercise: count words from file
- Solution: count characters
- Solution: count characters - sort by frequency
- Solution: count words
- Solution: count words from file
- Testing
- Testing in Go
- Testing modules
- Simple example with testing
- Test with failure
- Run selected test functions
- Exercise: Test Anagram
- Exercise: Test Calculator
- Exercise: statistics
- Solution: Test Anagram
- Solution: Test Calculator
- Solution: statistics
- Struct
- Struct and type
- Struct with partial information (default values)
- Slice of structs
- Anonymous struct
- Struct in a struct
- composition via embedding instead of inheritance
- Tags and introspection (reflect)
- use cleanenv
- methods
- method of int
- map keys method
- method gets copy of struct
- method pass pointer of struct
- Exercise: read-csv-struct
- Exercise: implement 2D point and move
- Exercise: implement 3D point and move
- Exercise: implement wc
- Solution: implement wc
- Logging
- Simple Logging
- Logging Fatal errors
- Logging to a file - rewrite
- Logging to a file - append
- Logging the filename
- Logging flags
- Logging: Set Prefix
- Turn logging on/off
- TODO: log levels?
- TODO: log function names
- TODO: logrotation
- Time
- Monolitic vs Wallclock time
- Time example
- Nanoseconds
- sleep and elapsed time
- Time format
- Date Arithmetic
- Pointers
- Integer assignment is copying (not pointer)
- Pointer to integer
- Array Pointer
- Slice Pointer and copy slice
- Panic (Exception handling)
- Panic
- We Panic
- Turn error into panic when port is used
- Panic after defer
- Recover (and re-panic)
- Recover from deep panic
- Convert panic to returned error
- Exercise: read several files
- Solution: read several files
- Goroutine
- Without goroutine
- goroutine example
- goroutine not finished yet
- goroutine no wait
- Global waitgroup for goroutines
- Wait for goroutines
- Return data from goroutines
- Counter - shared variable
- Mutex
- Channels
- Channels are blocking
- Channel capacity - buffered channel
- Channel with loop
- Pipeline map
- Pipeline filter
- TODO: Pipelines
- Fibonacci goroutine
- Loop from a channel
- Select channel
- Delayed start
- Job pool
- Check for race conditions
- Stand alone web application
- Maximum processes
- Exercise: Collect data from urls
- Exercise: Process multiple CSV files
- Exercise: counter with lock
- Exercise: Fibonacci in parallel
- Solution: Collect data from urls
- Functions 2
- Numbers passed by reference
- Array passed by value or by reference
- TODO: pass by value, pass by reference
- Variable declaration outside of functions
- Exercise: Fibonacci series
- Exercise: Permutations
- Exercise: 100 doors
- Solution: Fibonacci series
- Solution: Fibonacci recursive
- Solution: single counter
- Solution: Permutations
- Solution: 100 doors
- TODO return array
- Bitwise
- bitwise operators
- bitwise left shift
- bitwise not
- bitwise clear bit - AND NOT
- Formatting
- Println
- Sprintln
- Sprintf
- Padding and alignment
- Filesystem
- os.stat information about a file or directory (file exists)
- List Directory
- Get Current Working Directory (cwd)
- Create Temporary Directory
- Traverse directory tree
- Join parts of a directory or filepath
- Regular Expressions (Regexes, Regexp)
- Regexp
- Regexp
- Regex nomatch
- Regex Markua include
- Exercise: Parse ini file
- Exercise: parse hours log file and give report
- Solution: Parse ini file
- Solution: parse hours log file and give report
- Flow Control
- if-statements
- if, else, else if
- if with initializer
- Comparision Operators
- Short circuit
- switch
- type switch
- JSON
- JSON round trip
- Web client
- http get request
- URL parsing
- TODO Checking links of a web site
- TODO fteching youtube playlist
- HTTP GET failure
- HTTP Server
- HTTP Hello World
- HTTP Echo GET
- HTTP Echo POST
- text/template
- text/template with map
- text/template with struct
- text/template in file
- text/template if
- text/template loop
- html/template
- HTTP Hello World templates
- External programs
- Find executable (which where)
- Run external programs
- Run external program in the background
- Capture the outout of an external program
- Distribution
- Corss Compilation
- Packages
- Cross compile
- Environment variables
- Install packages
- Include and distribute external files
- go workspace layout
- Directory of 3rd party packages
- Semantic versioning
- go install
- Command line arguments (Flag)
- Flag
- Flags as pointers
- Flags as variables
- Appendix
- Some advanced topics
- Resources
- Caller filename
- os.Executable
- Solution: rectangular (STDIN) Reader
- Scan int
- Function assignment
- Overwriting built-in functions
- TODO: stack
- queue
- Left over
- Open Web browser
- Unicode
- golang create io.reader from string
- Parse HTML Token by token
- Parse HTML extract tags and attributes
- Other slides
- Print to STDERR or STDOUT
- Companies using Golang in Israel