This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/oschwald/geoip2-golang" | |
| "log" | |
| "net" | |
| "os" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| ) | |
| // An abstract type, i.e. an interface | |
| type shuffler interface { | |
| Len() int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| type SummableSlice []int | |
| func (s SummableSlice) sum() int { | |
| sum := 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "sync/atomic" | |
| "time" | |
| ) | |
| var ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "time" | |
| ) | |
| func reader(ch chan int) { | |
| t := time.NewTimer(10 * time.Second) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| func printer(msg string, stopCh chan bool) { | |
| for { | |
| select { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // There's no "channel broadcast" in Go, i.e. you can't send something to multiple goroutines using the same channel. However you can close the channel and all goroutines will be notified. | |
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| func printer(msg string, goCh chan bool) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| // emit words onto the channel until the timer kicks in | |
| func emit(wordChannel chan string) { | |
| defer close(wordChannel) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| // printArray prints type, elements' values, capacity and length of an array | |
| func printArray(a [3]int) { | |
| fmt.Printf("%T\t", a) | |
| for _, v := range a { | |
| fmt.Printf("%d ", v) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "--> create VMs..." | |
| for i in 1 2 3; do | |
| docker-machine create -d virtualbox node-$i | |
| done | |
| echo "--> initialize swarm master..." | |
| eval $(docker-machine env node-1) | |
| docker swarm init \ |