From 6750b72724ee9f6fec591b4c84ca7ae7ca1901fc Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sun, 23 Sep 2012 12:47:27 -0700 Subject: [PATCH] updates --- ...-synchronization.go => synchronization.go} | 0 040-select/{040-select.go => select.go} | 5 +++- .../timeouts.go | 5 +++- .../string-functions.go | 5 +++- 043-bytes/{043-bytes.go => bytes.go} | 2 ++ .../044-command-line-args.go | 25 ------------------ .../command-line-arguments.go | 26 +++++++++++++++++++ .../command-line-arguments.sh | 9 +++++++ ...limiting.go => burstable-rate-limiting.go} | 2 ++ 046-dns/046-dns.go | 7 ----- 047-elapsed/{047-elapsed.go => elapsed.go} | 5 +++- 048-email/{048-email.go => email.go} | 14 +++++----- .../{049-enumerable.go => enumerable.go} | 5 +++- tool/index.txt | 7 +++-- 14 files changed, 70 insertions(+), 47 deletions(-) rename 039-synchronization/{039-synchronization.go => synchronization.go} (100%) rename 040-select/{040-select.go => select.go} (92%) rename 041-timeout/041-timeout.go => 041-timeouts/timeouts.go (89%) rename 042-string-fns/042-string-fns.go => 042-string-functions/string-functions.go (90%) rename 043-bytes/{043-bytes.go => bytes.go} (92%) delete mode 100644 044-command-line-args/044-command-line-args.go create mode 100644 044-command-line-arguments/command-line-arguments.go create mode 100644 044-command-line-arguments/command-line-arguments.sh rename 045-burstable-rate-limiting/{045-burstable-rate-limiting.go => burstable-rate-limiting.go} (92%) delete mode 100644 046-dns/046-dns.go rename 047-elapsed/{047-elapsed.go => elapsed.go} (70%) rename 048-email/{048-email.go => email.go} (54%) rename 049-enumerable/{049-enumerable.go => enumerable.go} (97%) diff --git a/039-synchronization/039-synchronization.go b/039-synchronization/synchronization.go similarity index 100% rename from 039-synchronization/039-synchronization.go rename to 039-synchronization/synchronization.go diff --git a/040-select/040-select.go b/040-select/select.go similarity index 92% rename from 040-select/040-select.go rename to 040-select/select.go index 6698196..5c6398e 100644 --- a/040-select/040-select.go +++ b/040-select/select.go @@ -1,6 +1,9 @@ +// ## Select + package main -import ("fmt"; "time") +import "time" +import "fmt" func main() { c1 := make(chan string) diff --git a/041-timeout/041-timeout.go b/041-timeouts/timeouts.go similarity index 89% rename from 041-timeout/041-timeout.go rename to 041-timeouts/timeouts.go index 95234bb..8c5f43e 100644 --- a/041-timeout/041-timeout.go +++ b/041-timeouts/timeouts.go @@ -1,6 +1,9 @@ +// ## Timeouts + package main -import ("fmt"; "time") +import "time" +import "fmt" func main() { c := make(chan string) diff --git a/042-string-fns/042-string-fns.go b/042-string-functions/string-functions.go similarity index 90% rename from 042-string-fns/042-string-fns.go rename to 042-string-functions/string-functions.go index f9078b1..15e67de 100644 --- a/042-string-fns/042-string-fns.go +++ b/042-string-functions/string-functions.go @@ -1,6 +1,9 @@ +// ## String Functions + package main -import ("fmt"; "strings") +import "strings" +import "fm" func p(o interface{}) { fmt.Println(o) diff --git a/043-bytes/043-bytes.go b/043-bytes/bytes.go similarity index 92% rename from 043-bytes/043-bytes.go rename to 043-bytes/bytes.go index e7126fb..3eab9a2 100644 --- a/043-bytes/043-bytes.go +++ b/043-bytes/bytes.go @@ -1,3 +1,5 @@ +// ## Bytes + package main import "fmt" diff --git a/044-command-line-args/044-command-line-args.go b/044-command-line-args/044-command-line-args.go deleted file mode 100644 index 03244ad..0000000 --- a/044-command-line-args/044-command-line-args.go +++ /dev/null @@ -1,25 +0,0 @@ -package main // Use `os.Args` to access command-line arguments and - // the name of the program. -import ("os"; "fmt") - -func main() { - argsWithProg := os.Args // `os.Args` includes the program name as the first - argsWithoutProg := os.Args[1:] // value. - - arg := os.Args[3] // `Args` are a slice, you can get individual args - // with normal indexing. - - fmt.Println(argsWithProg) - fmt.Println(argsWithoutProg) - fmt.Println(arg) -} - -/* -$ go build command-line-args // Build a `command-line-args` binary so that we have - // the expected program name. - -$ ./command-line-args a b c d -[command-line-args a b c d] -[a b c d] -c -*/ diff --git a/044-command-line-arguments/command-line-arguments.go b/044-command-line-arguments/command-line-arguments.go new file mode 100644 index 0000000..c5bfdda --- /dev/null +++ b/044-command-line-arguments/command-line-arguments.go @@ -0,0 +1,26 @@ +// ## Command Line Arguments + +// Use `os.Args` to access command-line arguments and +// the name of the program. +package main + +import "os" +import "fmt" + +func main() { + // `os.Args` includes the program name as the first + // value. + argsWithProg := os.Args + argsWithoutProg := os.Args[1:] + + // `Args` are a slice, you can get individual args + // with normal indexing. + arg := os.Args[3] + + + fmt.Println(argsWithProg) + fmt.Println(argsWithoutProg) + fmt.Println(arg) +} + +// todo: discuss building before here diff --git a/044-command-line-arguments/command-line-arguments.sh b/044-command-line-arguments/command-line-arguments.sh new file mode 100644 index 0000000..66977b8 --- /dev/null +++ b/044-command-line-arguments/command-line-arguments.sh @@ -0,0 +1,9 @@ +# Build a `command-line-args` binary so that we have +# the expected program name. +$ go build command-line-arguments + + +$ ./command-line-arguments a b c d +[command-line-arguments a b c d] +[a b c d] +c diff --git a/045-burstable-rate-limiting/045-burstable-rate-limiting.go b/045-burstable-rate-limiting/burstable-rate-limiting.go similarity index 92% rename from 045-burstable-rate-limiting/045-burstable-rate-limiting.go rename to 045-burstable-rate-limiting/burstable-rate-limiting.go index a74b8eb..4c19bcd 100644 --- a/045-burstable-rate-limiting/045-burstable-rate-limiting.go +++ b/045-burstable-rate-limiting/burstable-rate-limiting.go @@ -1,3 +1,5 @@ +// ## Burstable Rate Limiting + package main import "time" diff --git a/046-dns/046-dns.go b/046-dns/046-dns.go deleted file mode 100644 index 47e1af2..0000000 --- a/046-dns/046-dns.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import ("net/dns", "fmt") - -func main() { - // https://github.com/miekg/dns/blob/master/ex/q/q.go -} diff --git a/047-elapsed/047-elapsed.go b/047-elapsed/elapsed.go similarity index 70% rename from 047-elapsed/047-elapsed.go rename to 047-elapsed/elapsed.go index e5ee6d3..66345a1 100644 --- a/047-elapsed/047-elapsed.go +++ b/047-elapsed/elapsed.go @@ -1,6 +1,9 @@ +// ## Elapsed Time + package main -import ("time"; "fmt") +import "time" +import "fmt" func main() { start := time.Now() diff --git a/048-email/048-email.go b/048-email/email.go similarity index 54% rename from 048-email/048-email.go rename to 048-email/email.go index 4c2e433..f467edb 100644 --- a/048-email/048-email.go +++ b/048-email/email.go @@ -1,8 +1,8 @@ +// ## Email + package main -import ( - "net/smtp" -) +import "net/smtp" func main() { auth := smtp.PlainAuth( @@ -17,10 +17,12 @@ func main() { auth, "mark+sent@heroku.com", []string{"mark@heroku.com"}, - []byte("The Subject\r\n\r\nThe Body"), + []byte("nThe body."), ) if err != nil { panic(err) } } -// missing subject, cc, bcc, attachements, plain/multi-type emails -// https://github.com/mtoader/google-go-lang-idea-plugin/issues/112 +// todo: missing subject, cc, bcc +// todo: attachements +// todo: plain/multi-type emails +// todo: https://github.com/mtoader/google-go-lang-idea-plugin/issues/112 diff --git a/049-enumerable/049-enumerable.go b/049-enumerable/enumerable.go similarity index 97% rename from 049-enumerable/049-enumerable.go rename to 049-enumerable/enumerable.go index 2d0cc5c..e126825 100644 --- a/049-enumerable/049-enumerable.go +++ b/049-enumerable/enumerable.go @@ -1,6 +1,9 @@ +// ## Enumerable + package main -import ("fmt"; "strings") +import "strings" +import "fmt" func Index(elems []string, val string) int { for i, v := range elems { diff --git a/tool/index.txt b/tool/index.txt index c8b3140..5135a9c 100644 --- a/tool/index.txt +++ b/tool/index.txt @@ -38,12 +38,11 @@ buffering directions synchronization select -timeout -string-fns +timeouts +string-functions bytes -command-line-args +command-line-arguments burstable-rate-limiting -dns elapsed email enumerable