Created
July 31, 2014 06:13
-
-
Save sbward/e03956c033bbdfa03a37 to your computer and use it in GitHub Desktop.
Code sample from your house
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 ( | |
"flag" | |
"fmt" | |
"math/rand" | |
"strconv" | |
"sync" | |
) | |
type car struct { | |
color string | |
year int | |
} | |
type dog struct { | |
name string | |
age int | |
} | |
func main() { | |
var debug *bool | |
debug = flag.Bool("d", false, "Debugging enabled?") | |
flag.Parse() | |
greeting, number := "I am Andrew", getFavoriteNumber() | |
greeting = greeting + " and my favorite number is " + strconv.Itoa(number) | |
wg := sync.WaitGroup{} | |
wg.Add(1) | |
go printGreeting(greeting, &wg) | |
wg.Wait() | |
if *debug { | |
cDog := dog{"stumps", 1} | |
nDog := dog{"champagne", 2001} | |
fmt.Println(cDog, nDog) | |
} | |
} | |
func printGreeting(greeting string, wg *sync.WaitGroup) { | |
fmt.Println(greeting) | |
wg.Done() | |
} | |
func getFavoriteNumber() int { | |
return rand.Int() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment