updates
This commit is contained in:
parent
35c4455331
commit
e91edf0194
@ -1,11 +1,11 @@
|
||||
// ## Postgres
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/bmizerany/pq"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
import _ "github.com/bmizerany/pq"
|
||||
import "database/sql"
|
||||
import "time"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
db, openErr := sql.Open("postgres", "dbname=gobyexample sslmode=disable")
|
||||
@ -50,16 +50,7 @@ func main() {
|
||||
fmt.Println(dropRep)
|
||||
}
|
||||
|
||||
// == running
|
||||
// # start postgres
|
||||
// $ createdb gobyexample
|
||||
// $ cd xx-postgres
|
||||
// $ go get
|
||||
// $ ./xx-postgres
|
||||
|
||||
// == todo
|
||||
// connection pooling
|
||||
// concurrency
|
||||
// re-connection
|
||||
// errors
|
||||
// explain
|
||||
// todo: connection pooling & concurrency
|
||||
// todo: re-connection
|
||||
// todo: errors
|
||||
// todo: database_url
|
10
076-postgres/postgres.sh
Normal file
10
076-postgres/postgres.sh
Normal file
@ -0,0 +1,10 @@
|
||||
# First, be sure that you've installed Postgres
|
||||
# and have a server running locally at port 5432.
|
||||
|
||||
# Then create an example database.
|
||||
$ createdb gobyexample
|
||||
|
||||
# Now install the dependencies for the postgres
|
||||
# example and try running it.
|
||||
$ go get github.com/bmizerany/pq
|
||||
$ go run postgres.go
|
@ -1,37 +0,0 @@
|
||||
package main // The `math/rand` package provides psuedo-random
|
||||
// numbers.
|
||||
import (
|
||||
"math/rand"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Print(rand.Intn(100), ",") // For example, `rand.Intn` returns a random `int` n,
|
||||
fmt.Print(rand.Intn(100)) // `0 <= n < 100`.
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println(rand.Float64()) // `rand.Float64` returns a `float64` `f`,
|
||||
// `0.0 <= f < 1.0`.
|
||||
|
||||
s1 := rand.NewSource(42) // To make the psuedo-random generator deterministic,
|
||||
r1 := rand.New(s1) // give it a well-known seed.
|
||||
|
||||
|
||||
fmt.Print(r1.Intn(100), ",") // Call the resulting `rand.Source` just like the
|
||||
fmt.Print(r1.Intn(100)) // functions on the `rand` package.
|
||||
fmt.Println()
|
||||
|
||||
s2 := rand.NewSource(42) // If you seed a source with the same number, it
|
||||
r2 := rand.New(s2) // produces the same sequence of random numbers.
|
||||
fmt.Print(r2.Intn(100), ",")
|
||||
fmt.Print(r2.Intn(100))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
/*
|
||||
$ go run rand.go
|
||||
81,87
|
||||
0.6645600532184904
|
||||
5,87
|
||||
5,87
|
||||
*/
|
39
077-rand/rand.go
Normal file
39
077-rand/rand.go
Normal file
@ -0,0 +1,39 @@
|
||||
// Rand
|
||||
|
||||
package main
|
||||
|
||||
// The `math/rand` package provides psuedo-random
|
||||
// numbers.
|
||||
import "math/rand"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// For example, `rand.Intn` returns a random `int` n,
|
||||
// `0 <= n < 100`.
|
||||
fmt.Print(rand.Intn(100), ",")
|
||||
fmt.Print(rand.Intn(100))
|
||||
fmt.Println()
|
||||
|
||||
// `rand.Float64` returns a `float64` `f`,
|
||||
// `0.0 <= f < 1.0`.
|
||||
fmt.Println(rand.Float64())
|
||||
|
||||
// To make the psuedo-random generator deterministic,
|
||||
// give it a well-known seed.
|
||||
s1 := rand.NewSource(42)
|
||||
r1 := rand.New(s1)
|
||||
|
||||
// Call the resulting `rand.Source` just like the
|
||||
// functions on the `rand` package.
|
||||
fmt.Print(r1.Intn(100), ",")
|
||||
fmt.Print(r1.Intn(100))
|
||||
fmt.Println()
|
||||
|
||||
// If you seed a source with the same number, it
|
||||
// produces the same sequence of random numbers.
|
||||
s2 := rand.NewSource(42)
|
||||
r2 := rand.New(s2)
|
||||
fmt.Print(r2.Intn(100), ",")
|
||||
fmt.Print(r2.Intn(100))
|
||||
fmt.Println()
|
||||
}
|
5
077-rand/rand.sh
Normal file
5
077-rand/rand.sh
Normal file
@ -0,0 +1,5 @@
|
||||
$ go run rand.go
|
||||
81,87
|
||||
0.6645600532184904
|
||||
5,87
|
||||
5,87
|
@ -1,6 +1,8 @@
|
||||
// ## Rate Limiting
|
||||
package main
|
||||
|
||||
import ("time"; "fmt")
|
||||
import "time"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
throttle := time.Tick(time.Millisecond * 200)
|
||||
@ -10,6 +12,4 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// == todo
|
||||
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting
|
||||
// todo: credit http://code.google.com/p/go-wiki/wiki/RateLimiting
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user