gopl

module
v0.0.0-...-fa54de9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2022 License: MIT

README

Learn GOPL - Go Programming Language

This repository contain Go programs that I wrote while learning the language. My main study references are

  • "The Go Programming Language" book.
  • "Learn How To Code: Google's Go (golang) Programming Language" Udemy Course by Todd McLeod.
  • "Go in Practice" book written by Matt Butcher and Matt Farina.
  • "Golang Tutorial for Beginners" by techworldwithnana youtube course.

Directories

Path Synopsis
gopl_book
ch1/dup1
dup programs reads the lines entered in the standard input and prints the text of the lines that appear more than once preceded by their count
dup programs reads the lines entered in the standard input and prints the text of the lines that appear more than once preceded by their count
ch1/dup2
dup2 prints the count and text of lines that appear more than once in the input.
dup2 prints the count and text of lines that appear more than once in the input.
ch1/dup3
The previous 2 versions of dup operate in a streaming mode in which input is read and broken into lines as needed, so in principle those programs can handle an arbitrary number of input.
The previous 2 versions of dup operate in a streaming mode in which input is read and broken into lines as needed, so in principle those programs can handle an arbitrary number of input.
ch1/echo1
echo program prints on the console its command line arguments like the Unix echo command
echo program prints on the console its command line arguments like the Unix echo command
ch1/echo2
This program illustrates a different variant of echo program
This program illustrates a different variant of echo program
ch1/echo3
echo program using String Join function
echo program using String Join function
ch1/exercise
Modify the echo program to print the index and value of each of its arguments, one per line
Modify the echo program to print the index and value of each of its arguments, one per line
todd_udemy_course
goplayground/application/JSONMarshal
Marshaling is the process of transforming the memory representation of an object to a data format suitable for storage or transmission, and it is typically used when data must be moved between different parts of a computer program or from one program to another.
Marshaling is the process of transforming the memory representation of an object to a data format suitable for storage or transmission, and it is typically used when data must be moved between different parts of a computer program or from one program to another.
goplayground/application/bcrypt
bcrypt is a password hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher.
bcrypt is a password hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher.
goplayground/application/sort/customSort
To illustrate how to sort on fields in a struct using Sort func by implementing the sort package interface "Interface"
To illustrate how to sort on fields in a struct using Sort func by implementing the sort package interface "Interface"
goplayground/application/sort/simpleSort
The sort package allows us to sort slices
The sort package allows us to sort slices
goplayground/array
Main thing to note about arrays in Go is size is part of the type as illustrated below
Main thing to note about arrays in Go is size is part of the type as illustrated below
goplayground/concurrency/atomic
Remember the Go Lang's Motto on Concurrency: "Share memory by communicating; Don't communicate by sharing memory."
Remember the Go Lang's Motto on Concurrency: "Share memory by communicating; Don't communicate by sharing memory."
goplayground/concurrency/mutex
A “mutex” is a mutual exclusion lock.
A “mutex” is a mutual exclusion lock.
goplayground/concurrency/raceCondition
Race condition occurs when two parallely executing entities try to access the same shared memory for read/write operation.
Race condition occurs when two parallely executing entities try to access the same shared memory for read/write operation.
goplayground/exercises/ninjaL5Ex4
Write a program to demonstrate anonymous struct
Write a program to demonstrate anonymous struct
goplayground/exercises/ninjaL6Ex1
create a func with the identifier foo that returns an int create a func with the identifier bar that returns an int and a string call both funcs print out their results
create a func with the identifier foo that returns an int create a func with the identifier bar that returns an int and a string call both funcs print out their results
goplayground/exercises/ninjaL6Ex5
create a type ​SQUARE create a type ​CIRCLE attach a method to each that calculates ​AREA​ and returns it create a type ​SHAPE​ that defines an interface as anything that has the ​AREA​ method create a func ​INFO​ which takes type shape and then prints the area create a value of type square create a value of type circle use func info to print the area of square use func info to print the area of circle
create a type ​SQUARE create a type ​CIRCLE attach a method to each that calculates ​AREA​ and returns it create a type ​SHAPE​ that defines an interface as anything that has the ​AREA​ method create a func ​INFO​ which takes type shape and then prints the area create a value of type square create a value of type circle use func info to print the area of square use func info to print the area of circle
goplayground/exercises/ninjaL6Ex8
Create a func which returns a func Assign the returned func to a variable Call the returned func
Create a func which returns a func Assign the returned func to a variable Call the returned func
goplayground/exercises/ninjaL7Ex2
create a person struct create a func called “changeMe” with a *person as a parameter change the value stored at the *person address create a value of type person & print out the value Call changeMe function
create a person struct create a func called “changeMe” with a *person as a parameter change the value stored at the *person address create a value of type person & print out the value Call changeMe function
goplayground/exercises/ninjaL9Ex1
In addition to the main goroutine, launch two additional goroutines
In addition to the main goroutine, launch two additional goroutines
goplayground/functions/anonymous
Anonymous self executing functions
Anonymous self executing functions
goplayground/functions/callback
Call function is a function that's passed into another function as an argument.
Call function is a function that's passed into another function as an argument.
goplayground/functions/closures
Go functions may be closures.
Go functions may be closures.
goplayground/functions/defer
A "defer" statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function executed a return statement, reached the end of its function body, or because the corresponding goroutine is panicking.
A "defer" statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function executed a return statement, reached the end of its function body, or because the corresponding goroutine is panicking.
goplayground/functions/funcExpressions
Functions are first class types in Go.
Functions are first class types in Go.
goplayground/functions/interfaceAndPolymorphism
In other words, what an interface tells a type is, "If you have methods that match my functions, then you are my type"
In other words, what an interface tells a type is, "If you have methods that match my functions, then you are my type"
goplayground/functions/recursion
Recursion happens when a function calls itself.
Recursion happens when a function calls itself.
goplayground/functions/returnFunc
Functions are first class types in Go and hence can be returned from a function just like any other type
Functions are first class types in Go and hence can be returned from a function just like any other type
goplayground/functions/unfurlingSlice
When we have a slice of some type, we can pass in the individual values in a slice by using the “...” operator.
When we have a slice of some type, we can pass in the individual values in a slice by using the “...” operator.
goplayground/functions/variadicFunction
We can create a function which takes an unlimited number of arguments Parameter that can accept unlimited number of arguments is known as a “variadic parameter.” We use the lexical element operator ...T to specify variadic parameter of type T
We can create a function which takes an unlimited number of arguments Parameter that can accept unlimited number of arguments is known as a “variadic parameter.” We use the lexical element operator ...T to specify variadic parameter of type T
goplayground/iota
Within a constant declaration, the predeclared identifier iota represents successive untyped integer constants.
Within a constant declaration, the predeclared identifier iota represents successive untyped integer constants.
goplayground/maps
Like slices, maps hold references to an underlying data structure.
Like slices, maps hold references to an underlying data structure.
goplayground/methodSet
IMPORTANT: “The method set of a type determines the INTERFACES
IMPORTANT: “The method set of a type determines the INTERFACES
goplayground/methods
Go function signature func (r receiver) identifier(parameters) (return(s)) { code }
Go function signature func (r receiver) identifier(parameters) (return(s)) { code }
goplayground/pointers
A pointer is a variable that holds the address of a memory location
A pointer is a variable that holds the address of a memory location
goplayground/slices/slice
A SLICE holds VALUES of the same TYPE.
A SLICE holds VALUES of the same TYPE.
goplayground/strings2
* As we saw, indexing a string yields its bytes, not its characters: * a string is just a bunch of bytes.
* As we saw, indexing a string yields its bytes, not its characters: * a string is just a bunch of bytes.
goplayground/struct
Structs allow us to compose together values of different types.
Structs allow us to compose together values of different types.
goplayground/switch
* In Go, we don't need to add break in every switch case as we do in C/C++ * That's the default behavior.
* In Go, we don't need to add break in every switch case as we do in C/C++ * That's the default behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL