updates
This commit is contained in:
parent
70dd607774
commit
6750b72724
@ -1,6 +1,9 @@
|
|||||||
|
// ## Select
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("fmt"; "time")
|
import "time"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c1 := make(chan string)
|
c1 := make(chan string)
|
@ -1,6 +1,9 @@
|
|||||||
|
// ## Timeouts
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("fmt"; "time")
|
import "time"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := make(chan string)
|
c := make(chan string)
|
@ -1,6 +1,9 @@
|
|||||||
|
// ## String Functions
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("fmt"; "strings")
|
import "strings"
|
||||||
|
import "fm"
|
||||||
|
|
||||||
func p(o interface{}) {
|
func p(o interface{}) {
|
||||||
fmt.Println(o)
|
fmt.Println(o)
|
@ -1,3 +1,5 @@
|
|||||||
|
// ## Bytes
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
@ -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
|
|
||||||
*/
|
|
26
044-command-line-arguments/command-line-arguments.go
Normal file
26
044-command-line-arguments/command-line-arguments.go
Normal 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
|
9
044-command-line-arguments/command-line-arguments.sh
Normal file
9
044-command-line-arguments/command-line-arguments.sh
Normal 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
|
@ -1,3 +1,5 @@
|
|||||||
|
// ## Burstable Rate Limiting
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "time"
|
import "time"
|
@ -1,7 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import ("net/dns", "fmt")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// https://github.com/miekg/dns/blob/master/ex/q/q.go
|
|
||||||
}
|
|
@ -1,6 +1,9 @@
|
|||||||
|
// ## Elapsed Time
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("time"; "fmt")
|
import "time"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
start := time.Now()
|
start := time.Now()
|
@ -1,8 +1,8 @@
|
|||||||
|
// ## Email
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "net/smtp"
|
||||||
"net/smtp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
auth := smtp.PlainAuth(
|
auth := smtp.PlainAuth(
|
||||||
@ -17,10 +17,12 @@ func main() {
|
|||||||
auth,
|
auth,
|
||||||
"mark+sent@heroku.com",
|
"mark+sent@heroku.com",
|
||||||
[]string{"mark@heroku.com"},
|
[]string{"mark@heroku.com"},
|
||||||
[]byte("The Subject\r\n\r\nThe Body"),
|
[]byte("nThe body."),
|
||||||
)
|
)
|
||||||
if err != nil { panic(err) }
|
if err != nil { panic(err) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// missing subject, cc, bcc, attachements, plain/multi-type emails
|
// todo: missing subject, cc, bcc
|
||||||
// https://github.com/mtoader/google-go-lang-idea-plugin/issues/112
|
// todo: attachements
|
||||||
|
// todo: plain/multi-type emails
|
||||||
|
// todo: https://github.com/mtoader/google-go-lang-idea-plugin/issues/112
|
@ -1,6 +1,9 @@
|
|||||||
|
// ## Enumerable
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("fmt"; "strings")
|
import "strings"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func Index(elems []string, val string) int {
|
func Index(elems []string, val string) int {
|
||||||
for i, v := range elems {
|
for i, v := range elems {
|
@ -38,12 +38,11 @@ buffering
|
|||||||
directions
|
directions
|
||||||
synchronization
|
synchronization
|
||||||
select
|
select
|
||||||
timeout
|
timeouts
|
||||||
string-fns
|
string-functions
|
||||||
bytes
|
bytes
|
||||||
command-line-args
|
command-line-arguments
|
||||||
burstable-rate-limiting
|
burstable-rate-limiting
|
||||||
dns
|
|
||||||
elapsed
|
elapsed
|
||||||
email
|
email
|
||||||
enumerable
|
enumerable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user