Edward's Tech Site this site made with Next.js 13 , see the code HOWTO: Jul 14 - Go
Notes on Joe Marini's Learning the Go Standard Library course
infoscourse videos are here: my code examples from this course are here: SECTION 0: Introduction Don't go re-inventing the wheel Go's concurrencyone of its standout features designed to make it easy to write programs that can perform multiple tasks simultaneously based on goroutines and channels inspired by Communicating Sequential Processes (CSP) goroutineslightweight threads cheaper in terms of memory and computational resources compared to traditional OS threads prefix a new goroutine with a go keyword channelsprovide a way for goroutines to communicate with each other send and receive values use the make function select statementallows a goroutine to wait on operations select blocksuntil one of its cases can proceed like a switch synchronizationprovides traditional synchronization primitives like sync.Mutex, sync.WaitGroup, and sync.Cond from the sync package also has many packages What you should know Setting up the environment installs Gohe has go1.15.6 on windows/amd64 I have go1.22.1 windows/amd64 VSCode Overview of Go packages he's here can't cover alljust most common packagesfmt strings, strconv, unicode math, random os ioutil url, http, encoding/json, encoding/xml SECTION 1: Formatting with fmt SECTION 2: Working with Strings The strings package documentation: string funcs other packes work with strings strings - searching, manipulating strconv - convert unicode - check Basic string operations iterate over characters in a string you can compare also with Compare also equalFoldcompare two strings in a case-insensitive manner ToUpper, ToLower String searching String manipulation Split() Join() runean alias for the int32 type and represents a single Unicode character Fields and FieldsFunc (callback) Replace uses a Replacer Using the Map function Caesar ciphera simple substitution encryption technique where each letter in the plaintext is shifted a fixed number of positions down or up the alphabet using strings.Map to encode Using string builder strings.Builder, like StringBuilder in C#more efficient when creating large strings Parsing strings with strconv Itoa for Integer-to-String is for historic and compatibility reasons with C, i.e. Integer-to-ASCII note that string() will not convert a number to its string equivalent strconv.Atoi goes the other direction other functions start with Parse the other way is Format String tests with Unicode documentation for unicode package checks for each also range tables check it like this SECTION 3: Mathematical Operations SECTION 4: Files and Directories File information documentation os package checkFileExists learnTech:fileExistsCompound learnTech:fileSizeModtime Writing files his and my way now he's doing basically the same thing learnTech:writefileingo Reading files learnTech:thewritetofile222 he reads chunk by chunk Directory operations learnTech:thewritotidir learnTech:getalljsonsfiles Temporary files and directories os.TempDir() is your temporary directory you are required to delete files you create here writes data there note that it's a random name: also ioutil.TempDir() the ioutil and os packages serve different purposes and are not entirely redundant, although they do overlap in some functionalities related to file operations SECTION 5: Networking