--- /dev/null
+package main
+
+import "fmt"
+
+func main() {
+ var array [2]string
+ array[0] = "HELLO"
+ array[1] = "GO"
+
+ fmt.Println(array[0], array[1])
+ fmt.Println(array)
+
+ var a int = 1
+ fmt.Println(a)
+ b := [2]string{"haha", "hehe"}
+ var c [2]string = [2]string{"a", "b"}
+ // ERROR: var c [2]string = {"a", "b"}
+ fmt.Println(b)
+ fmt.Println(c)
+
+ // SLICE
+ d := []byte{'a', 'b', 'c'}
+ fmt.Println(d)
+ var e []string = []string{"a", "b", "c"}
+
+ for i := 0; i < len(e); i++ {
+ fmt.Println(e[i])
+ }
+}
import "math/rand"
import "time"
+func GetStr() (string, string) {
+ const stra = "Hello"
+ const strb string = "World"
+ return stra, strb
+}
+
+func PrintType() {
+ var a int
+ var b int32
+ var c int64
+ var d uint32
+ var e float32
+ var f bool
+ var g complex64
+ var h complex128
+
+ fmt.Printf("%T %T %T %T %T %T %T %T\n", a, b, c, d, e, f, g, h)
+}
+
func main() {
+ defer fmt.Println("----------------")
rand.Seed(time.Now().UnixNano())
- for i := 0; i < rand.Intn(10); i++ {
- fmt.Printf("Hello World\n")
+ for i := 0; i < rand.Intn(10)+1; i++ {
+ fmt.Println(GetStr())
}
+
+ PrintType()
}
--- /dev/null
+package main
+
+import "fmt"
+
+type Vertex struct {
+ X int
+ Y int
+}
+
+func main() {
+ v := Vertex{1, 2}
+ fmt.Println(v)
+
+ p := &v
+ p.X = 2
+ fmt.Println(v)
+}
--- /dev/null
+package main
+
+import (
+ "fmt"
+ "runtime"
+ "time"
+)
+
+func main() {
+ fmt.Print("Go runs on ")
+ switch os := runtime.GOOS; os {
+ case "darwin":
+ fmt.Println("OS X.")
+ case "linux":
+ fmt.Println("Linux.")
+ default:
+ // freebsd, openbsd,
+ // plan9, windows...
+ fmt.Printf("%s.", os)
+ }
+
+ t := time.Now()
+ switch {
+ case t.Hour() < 12:
+ fmt.Println("Good morning!")
+ case t.Hour() < 17:
+ fmt.Println("Good afternoon.")
+ default:
+ fmt.Println("Good evening.")
+ }
+
+}