├── 01_output ├── first.go └── last.go ├── 02_variables ├── first.go └── last.go ├── 03_functions ├── first.go └── last.go ├── 04_returns ├── first.go └── last.go ├── 05_structs ├── first.go └── last.go ├── 06_methods ├── first.go └── last.go ├── 07_timers ├── first.go └── last.go ├── 08_goroutines ├── first.go └── last.go ├── 09_channels ├── first.go └── last.go ├── 10_loops ├── first.go └── last.go ├── 11_input ├── first.go └── last.go └── README.md /01_output/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // TODO: Print "Hello World" using the fmt package 7 | } -------------------------------------------------------------------------------- /01_output/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hello World") 7 | } -------------------------------------------------------------------------------- /02_variables/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // TODO: Move "Hello World" into a variable 7 | fmt.Println("Hello World") 8 | } -------------------------------------------------------------------------------- /02_variables/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | message := "Hello World" 7 | fmt.Println(message) 8 | } -------------------------------------------------------------------------------- /03_functions/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // TODO: Make a "print" function 6 | 7 | func main() { 8 | print("Hello World") 9 | } -------------------------------------------------------------------------------- /03_functions/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func print(message string) { 6 | fmt.Println(message) 7 | } 8 | 9 | func main() { 10 | print("Hello World") 11 | } -------------------------------------------------------------------------------- /04_returns/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // TODO: Make a function that adds two numbers and returns the result 6 | 7 | func main() { 8 | fmt.Println(add(4, 5)) 9 | } -------------------------------------------------------------------------------- /04_returns/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func add(a int, b int) int { 6 | return a + b 7 | } 8 | 9 | func main() { 10 | fmt.Println(add(4, 5)) 11 | } -------------------------------------------------------------------------------- /05_structs/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // TODO: Define a Computer struct and it's properties 6 | 7 | func main() { 8 | computer := Computer{ 9 | Brand: "Apple", 10 | Model: "Macbook", 11 | Price: 1000, 12 | } 13 | 14 | fmt.Println(computer) 15 | } -------------------------------------------------------------------------------- /05_structs/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Computer struct { 6 | Brand string 7 | Model string 8 | Price int 9 | } 10 | 11 | func main() { 12 | computer := Computer{ 13 | Brand: "Apple", 14 | Model: "Macbook", 15 | Price: 1000, 16 | } 17 | 18 | fmt.Println(computer) 19 | } -------------------------------------------------------------------------------- /06_methods/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Computer struct { 6 | Brand string 7 | Model string 8 | Price int 9 | } 10 | 11 | // TODO: Create a "Describe" method that prints all the properties 12 | 13 | func main() { 14 | computer := Computer{ 15 | Brand: "Apple", 16 | Model: "Macbook", 17 | Price: 1000, 18 | } 19 | 20 | computer.Describe() 21 | } -------------------------------------------------------------------------------- /06_methods/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Computer struct { 6 | Brand string 7 | Model string 8 | Price int 9 | } 10 | 11 | func (c *Computer) Describe() { 12 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 13 | } 14 | 15 | func main() { 16 | computer := Computer{ 17 | Brand: "Apple", 18 | Model: "Macbook", 19 | Price: 1000, 20 | } 21 | 22 | computer.Describe() 23 | } -------------------------------------------------------------------------------- /07_timers/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | // TODO: Make a StartTimer function that... 19 | // - Sleeps for a given duration 20 | // - Prints a message when done 21 | 22 | func main() { 23 | computer := Computer{ 24 | Brand: "Apple", 25 | Model: "Macbook", 26 | Price: 1000, 27 | } 28 | 29 | t := 3 * time.Second 30 | computer.StartTimer(t) 31 | } -------------------------------------------------------------------------------- /07_timers/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | 21 | time.Sleep(t) 22 | 23 | fmt.Println("Time up!") 24 | } 25 | 26 | func main() { 27 | computer := Computer{ 28 | Brand: "Apple", 29 | Model: "Macbook", 30 | Price: 1000, 31 | } 32 | 33 | t := 3 * time.Second 34 | computer.StartTimer(t) 35 | } -------------------------------------------------------------------------------- /08_goroutines/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | fmt.Println("Time up!") 22 | } 23 | 24 | func main() { 25 | computer := Computer{ 26 | Brand: "Apple", 27 | Model: "Macbook", 28 | Price: 1000, 29 | } 30 | 31 | t := 3 * time.Second 32 | 33 | // TODO: Spawn this function in a goroutine 34 | computer.StartTimer(t) 35 | 36 | // IGNORE THIS: 37 | // This is a hack, so the program doesn't quit before the goroutine finishes 38 | time.Sleep(10 * time.Second) 39 | } -------------------------------------------------------------------------------- /08_goroutines/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | fmt.Println("Time up!") 22 | } 23 | 24 | func main() { 25 | computer := Computer{ 26 | Brand: "Apple", 27 | Model: "Macbook", 28 | Price: 1000, 29 | } 30 | 31 | t := 3 * time.Second 32 | go computer.StartTimer(t) 33 | 34 | // IGNORE THIS: 35 | // This is a hack, so the program doesn't quit before the goroutine finishes 36 | time.Sleep(10 * time.Second) 37 | } -------------------------------------------------------------------------------- /09_channels/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(channel chan string, t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | 22 | // TODO: Push the "Time up!" string to the channel 23 | } 24 | 25 | func main() { 26 | computer := Computer{ 27 | Brand: "Apple", 28 | Model: "Macbook", 29 | Price: 1000, 30 | } 31 | 32 | channel := make(chan string) 33 | 34 | t := 3 * time.Second 35 | go computer.StartTimer(channel, t) 36 | 37 | // Use "select" to listen to the channel and print the string 38 | 39 | fmt.Println("Exited") 40 | } 41 | -------------------------------------------------------------------------------- /09_channels/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(channel chan string, t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | channel <- "Time up!" 22 | } 23 | 24 | func main() { 25 | computer := Computer{ 26 | Brand: "Apple", 27 | Model: "Macbook", 28 | Price: 1000, 29 | } 30 | 31 | channel := make(chan bool) 32 | 33 | t := 3 * time.Second 34 | go computer.StartTimer(channel, t) 35 | 36 | select { 37 | case msg := <-channel: 38 | fmt.Println(msg) 39 | } 40 | 41 | fmt.Println("Exited") 42 | } -------------------------------------------------------------------------------- /10_loops/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(channel chan string, t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | channel <- "Time up!" 22 | } 23 | 24 | func (c *Computer) StartInterval(channel chan string, t time.Duration) { 25 | fmt.Println("Starting interval...") 26 | 27 | // TODO: Use a "for" loop to push a message to the channel every t seconds 28 | 29 | // TODO: Close the channel after the loop finishes 30 | } 31 | 32 | func main() { 33 | computer := Computer{ 34 | Brand: "Apple", 35 | Model: "Macbook", 36 | Price: 1000, 37 | } 38 | 39 | channel := make(chan string) 40 | 41 | t := 1 * time.Second 42 | go computer.StartInterval(channel, t) 43 | 44 | computer.Describe() 45 | 46 | // TODO: Use a "for" loop to watch for messages on the channel 47 | 48 | fmt.Println("Exited") 49 | } -------------------------------------------------------------------------------- /10_loops/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(channel chan string, t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | channel <- "Time up!" 22 | } 23 | 24 | func (c *Computer) StartInterval(channel chan string, t time.Duration) { 25 | fmt.Println("Starting interval...") 26 | 27 | for i := 0; i < 10; i++ { 28 | time.Sleep(t) 29 | channel <- fmt.Sprintf("Interval %d up!", i) 30 | } 31 | 32 | close(channel) 33 | } 34 | 35 | func main() { 36 | computer := Computer{ 37 | Brand: "Apple", 38 | Model: "Macbook", 39 | Price: 1000, 40 | } 41 | 42 | channel := make(chan string) 43 | 44 | t := 1 * time.Second 45 | go computer.StartInterval(channel, t) 46 | 47 | computer.Describe() 48 | 49 | for msg := range channel { 50 | fmt.Println(msg) 51 | } 52 | 53 | fmt.Println("Exited") 54 | } -------------------------------------------------------------------------------- /11_input/first.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(channel chan string, t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | channel <- "Time up!" 22 | } 23 | 24 | func (c *Computer) StartInterval(channel chan string, t time.Duration) { 25 | fmt.Println("Starting interval...") 26 | 27 | for i := 0; i < 10; i++ { 28 | time.Sleep(t) 29 | channel <- fmt.Sprintf("Interval %d up!", i) 30 | } 31 | 32 | close(channel) 33 | } 34 | 35 | func main() { 36 | computer := Computer{ 37 | Brand: "Apple", 38 | Model: "Macbook", 39 | Price: 1000, 40 | } 41 | 42 | channel := make(chan string) 43 | 44 | fmt.Printf("How long? ") 45 | 46 | // TODO: Get the number of seconds from user input 47 | 48 | t := time.Duration(seconds) * time.Second 49 | go computer.StartInterval(channel, t) 50 | 51 | for msg := range channel { 52 | fmt.Println(msg) 53 | } 54 | 55 | fmt.Println("Exited") 56 | } -------------------------------------------------------------------------------- /11_input/last.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | type Computer struct { 9 | Brand string 10 | Model string 11 | Price int 12 | } 13 | 14 | func (c *Computer) Describe() { 15 | fmt.Printf("%s %s $%d\n", c.Brand, c.Model, c.Price) 16 | } 17 | 18 | func (c *Computer) StartTimer(channel chan string, t time.Duration) { 19 | fmt.Println("Starting timer...") 20 | time.Sleep(t) 21 | channel <- "Time up!" 22 | } 23 | 24 | func (c *Computer) StartInterval(channel chan string, t time.Duration) { 25 | fmt.Println("Starting interval...") 26 | 27 | for i := 0; i < 10; i++ { 28 | time.Sleep(t) 29 | channel <- fmt.Sprintf("Interval %d up!", i) 30 | } 31 | 32 | close(channel) 33 | } 34 | 35 | func main() { 36 | computer := Computer{ 37 | Brand: "Apple", 38 | Model: "Macbook", 39 | Price: 1000, 40 | } 41 | 42 | channel := make(chan string) 43 | 44 | fmt.Printf("How long? ") 45 | 46 | var seconds int 47 | fmt.Scan(&seconds) 48 | 49 | t := time.Duration(seconds) * time.Second 50 | go computer.StartInterval(channel, t) 51 | 52 | for msg := range channel { 53 | fmt.Println(msg) 54 | } 55 | 56 | fmt.Println("Exited") 57 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sendwithus Go Workshop 2 | ====================== 3 | 4 | 5 | # [GET THE SLIDES](http://bit.ly/1OdrQUx) 6 | 7 | 8 | Import this into [Cloud 9](https://c9.io) 9 | 10 | -------------------- 11 | -------------------- 12 | -------------------- 13 | 14 | ![Golang Gopher](https://camo.githubusercontent.com/928db8e4006eb890439550efd35dc7358f98fc9c/68747470733a2f2f7261772e6769746875622e636f6d2f74656e6e74656e6e2f676f706865722d737469636b6572732f6d61737465722f737469636b6572732e706e67) 15 | --------------------------------------------------------------------------------