This commit is contained in:
Mark McGranaghan 2012-09-23 12:47:27 -07:00
parent 70dd607774
commit 6750b72724
14 changed files with 70 additions and 47 deletions

View File

@ -1,6 +1,9 @@
// ## Select
package main
import ("fmt"; "time")
import "time"
import "fmt"
func main() {
c1 := make(chan string)

View File

@ -1,6 +1,9 @@
// ## Timeouts
package main
import ("fmt"; "time")
import "time"
import "fmt"
func main() {
c := make(chan string)

View File

@ -1,6 +1,9 @@
// ## String Functions
package main
import ("fmt"; "strings")
import "strings"
import "fm"
func p(o interface{}) {
fmt.Println(o)

View File

@ -1,3 +1,5 @@
// ## Bytes
package main
import "fmt"

View File

@ -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
*/

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,5 @@
// ## Burstable Rate Limiting
package main
import "time"

View File

@ -1,7 +0,0 @@
package main
import ("net/dns", "fmt")
func main() {
// https://github.com/miekg/dns/blob/master/ex/q/q.go
}

View File

@ -1,6 +1,9 @@
// ## Elapsed Time
package main
import ("time"; "fmt")
import "time"
import "fmt"
func main() {
start := time.Now()

View File

@ -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

View File

@ -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 {

View File

@ -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