working on re-arranging
This commit is contained in:
parent
dfd2c39463
commit
785a0d123b
@ -1,12 +0,0 @@
|
||||
package main // Here's an example Go program.
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello world") // It prints `Hello world`.
|
||||
}
|
||||
|
||||
/*
|
||||
$ go run hello-world.go // Put this code in hello-world.go,
|
||||
Hello world // then use `go run` to run it.
|
||||
*/
|
11
001-hello-world/hello-world.go
Normal file
11
001-hello-world/hello-world.go
Normal file
@ -0,0 +1,11 @@
|
||||
// ## Hello World
|
||||
|
||||
// Here's an example Go program.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// It prints `Hello world`.
|
||||
func main() {
|
||||
fmt.Println("Hello world")
|
||||
}
|
2
001-hello-world/hello-world.sh
Normal file
2
001-hello-world/hello-world.sh
Normal file
@ -0,0 +1,2 @@
|
||||
$ go run hello-world.go
|
||||
Hello world
|
@ -1,26 +0,0 @@
|
||||
package main // Go has various value types, including strings,
|
||||
// different types of numbers, booleans, etc.
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello world") // Strings.
|
||||
fmt.Println("Hello " + "other")
|
||||
|
||||
fmt.Println("1+1 =", 1+1) // Integers and floats.
|
||||
fmt.Println("7.0/3.0 =", 7.0/3.0)
|
||||
|
||||
fmt.Println(true && false) // Booleans.
|
||||
fmt.Println(true || false)
|
||||
fmt.Println(!true)
|
||||
}
|
||||
|
||||
/*
|
||||
$ go run values.go
|
||||
Hello world
|
||||
Hello other
|
||||
1+1 = 2
|
||||
7.0/3.0 = 2.3333333333333335
|
||||
false
|
||||
true
|
||||
false
|
||||
*/
|
23
002-values/values.go
Normal file
23
002-values/values.go
Normal file
@ -0,0 +1,23 @@
|
||||
// ## Values
|
||||
|
||||
// Go has various value types, including strings,
|
||||
// different types of numbers, booleans, etc.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
// Here are some strings, which can be added together.
|
||||
fmt.Println("Hello world")
|
||||
fmt.Println("Hello " + "other")
|
||||
|
||||
// Some examples of integers and floats.
|
||||
fmt.Println("1+1 =", 1+1)
|
||||
fmt.Println("7.0/3.0 =", 7.0/3.0)
|
||||
|
||||
// And booleans, which work as you'd expect.
|
||||
fmt.Println(true && false)
|
||||
fmt.Println(true || false)
|
||||
fmt.Println(!true)
|
||||
}
|
8
002-values/values.sh
Normal file
8
002-values/values.sh
Normal file
@ -0,0 +1,8 @@
|
||||
$ go run values.go
|
||||
Hello world
|
||||
Hello other
|
||||
1+1 = 2
|
||||
7.0/3.0 = 2.3333333333333335
|
||||
false
|
||||
true
|
||||
false
|
@ -1,17 +0,0 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var x string = "Hello world" // `var` declares 1 or more variables. The type comes
|
||||
fmt.Println(x) // at the end.
|
||||
|
||||
var a, b int = 1, 2 // An example of declaring multiple `int` variables.
|
||||
fmt.Println(a, b)
|
||||
}
|
||||
|
||||
/*
|
||||
$ go run variables.go
|
||||
Hello world
|
||||
1 2
|
||||
*/
|
16
003-variables/variables.go
Normal file
16
003-variables/variables.go
Normal file
@ -0,0 +1,16 @@
|
||||
// ## Variables
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// `var` declares 1 or more variables. The type comes
|
||||
// at the end.
|
||||
var x string = "Hello world"
|
||||
fmt.Println(x)
|
||||
|
||||
// An example of declaring multiple `int` variables.
|
||||
var a, b int = 1, 2
|
||||
fmt.Println(a, b)
|
||||
}
|
1
003-variables/variables.sh
Normal file
1
003-variables/variables.sh
Normal file
@ -0,0 +1 @@
|
||||
go run variables.go
|
@ -1,17 +0,0 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var x string
|
||||
x = "first"
|
||||
fmt.Println(x)
|
||||
x = "second" // You can mutate variables in Go.
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
||||
/*
|
||||
$ go run mutation.go
|
||||
first
|
||||
second
|
||||
*/
|
16
004-mutation/mutation.go
Normal file
16
004-mutation/mutation.go
Normal file
@ -0,0 +1,16 @@
|
||||
// ## Mutation
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var x string
|
||||
x = "old"
|
||||
fmt.Println(x)
|
||||
|
||||
// You can mutate variables in Go by re-assigning the
|
||||
// variable to a new value.
|
||||
x = "new"
|
||||
fmt.Println(x)
|
||||
}
|
3
004-mutation/mutation.sh
Normal file
3
004-mutation/mutation.sh
Normal file
@ -0,0 +1,3 @@
|
||||
$ go run mutation.go
|
||||
old
|
||||
new
|
@ -1,16 +0,0 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
x := "Hello literal" // `x := val` is shorthand for `var x type = val`.
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
||||
/*
|
||||
$ go run literal.go
|
||||
Hello literal
|
||||
*/
|
||||
|
||||
// == todo
|
||||
// literal?
|
14
005-literals/literals.go
Normal file
14
005-literals/literals.go
Normal file
@ -0,0 +1,14 @@
|
||||
// ## Literals
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
// `x := val` is shorthand for `var x type = val`.
|
||||
x := "Hello literal"
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
||||
// todo: literal term?
|
2
005-literals/literals.sh
Normal file
2
005-literals/literals.sh
Normal file
@ -0,0 +1,2 @@
|
||||
$ go run literal.go
|
||||
Hello literal
|
@ -1,9 +0,0 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
const x string = "Hello World"
|
||||
|
||||
func main() {
|
||||
fmt.Println(x)
|
||||
}
|
15
006-constants/constants.go
Normal file
15
006-constants/constants.go
Normal file
@ -0,0 +1,15 @@
|
||||
// ## Constants
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Use `const` to declare a constant value.
|
||||
// Constants can be ...
|
||||
const x string = "Hello World"
|
||||
|
||||
func main() {
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
||||
// todo: research
|
2
006-constants/constants.sh
Normal file
2
006-constants/constants.sh
Normal file
@ -0,0 +1,2 @@
|
||||
$ go run constant.go
|
||||
Hello World
|
@ -1,3 +1,5 @@
|
||||
// ## Reading Input
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
3
007-reading-input/reading-input.sh
Normal file
3
007-reading-input/reading-input.sh
Normal file
@ -0,0 +1,3 @@
|
||||
$ go run reading-input.go
|
||||
Enter a number: 7
|
||||
7 * 2 = 14
|
28
008-for.go
28
008-for.go
@ -1,28 +0,0 @@
|
||||
package main // `for` is Go's only looping construct. Below are
|
||||
// two common forms.
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
i := 1 // Initialize `i` with `1` and loop until it's 10.
|
||||
for i <= 3 {
|
||||
fmt.Print(i)
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
for j := 1; j <= 3; j++ { // That type of loop is common. We can do it on one
|
||||
fmt.Print(j) // line.
|
||||
}
|
||||
|
||||
for { // `for` without a condition will loop until you
|
||||
fmt.Println() // `return`.
|
||||
return
|
||||
}
|
||||
} // We'll see other `for` forms latter.
|
||||
|
||||
/*
|
||||
$ go run for.go
|
||||
123123
|
||||
*/
|
||||
|
||||
// == todo
|
||||
// break out of for loop?
|
34
008-for/for.go
Normal file
34
008-for/for.go
Normal file
@ -0,0 +1,34 @@
|
||||
// ## For
|
||||
|
||||
// `for` is Go's only looping construct. Here are
|
||||
// two common forms.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialize `i` with `1` and loop until it's 10.
|
||||
i := 1
|
||||
for i <= 3 {
|
||||
fmt.Print(i)
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
// That type of loop is common. We can do it on one
|
||||
// line.
|
||||
for j := 1; j <= 3; j++ {
|
||||
fmt.Print(j)
|
||||
}
|
||||
|
||||
// `for` without a condition will loop until you
|
||||
// `return`.
|
||||
for {
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// We'll see other `for` forms latter.
|
||||
|
||||
// todo: break out of for loop?
|
2
008-for/for.sh
Normal file
2
008-for/for.sh
Normal file
@ -0,0 +1,2 @@
|
||||
$ go run for.go
|
||||
123123
|
@ -34,5 +34,4 @@ func main() {
|
||||
fmt.Println(rectangle.area())
|
||||
}
|
||||
|
||||
// == todo
|
||||
// pointer vs value receivers
|
||||
// todo: pointer vs value receivers
|
@ -50,6 +50,5 @@ func main() {
|
||||
fmt.Println(area)
|
||||
}
|
||||
|
||||
// == todo
|
||||
// is this named wrong?
|
||||
// note about embedding access
|
||||
// todo: is this named wrong?
|
||||
// todo: note about embedding access
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import ("time"; "fmt")
|
||||
import "time"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
tick := time.Tick(time.Millisecond * 200)
|
||||
@ -21,5 +22,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
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user