标签:arw app package darwin highlight get ber window str
go time and rand:
package main import ( "fmt" "math/rand" "time" ) func main() { rand.Seed(time.Now().Unix()) fmt.Println("My favorite number is :", rand.Int()%20) }
get the runtime os:
package main import ( "fmt" "runtime" ) func main() { fmt.Println("Go runs on") switch os := runtime.GOOS; os { case "darwin": fmt.Println("os x") case "linux": fmt.Println("Linux.") default: fmt.Println("windows") } }
slice operator
package main import ( "fmt" // "reflect" ) func printSlice(s string, x []int) { fmt.Printf("%s len=%d cap=%d %v\n", s, len(x), cap(x), x) } func main() { var a []int printSlice("a", a) //append works on nil slice a = append(a, 0) printSlice("a", a) a = append(a, 2, 3, 4) printSlice("a", a) }
标签:arw app package darwin highlight get ber window str
原文地址:https://www.cnblogs.com/learn-ops/p/9655858.html