摘要: 常见用法 var ages map[string]int // 只声明不初始化是nil,赋值会panic: assignment to entry in nil map fmt.Println(ages == nil) // "true" fmt.Println(len(ages) == 0) // 阅读全文
posted @ 2023-02-19 22:00 roadwide 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 常用函数 t, err := time.Parse(layout,date) // time.Time, error t := time.Date(1995,time.September,22,13,0,0,0,time.UTC) formatedTime := t.Format("Mon, 01/ 阅读全文
posted @ 2023-02-19 21:42 roadwide 阅读(12) 评论(0) 推荐(0) 编辑
摘要: import "math/rand" n := rand.Intn(100) // n is a random int, 0 <= n < 100 f := rand.Float64() // f is a random float64, 0.0 <= f < 1.0 x := []string{" 阅读全文
posted @ 2023-02-19 16:17 roadwide 阅读(12) 评论(0) 推荐(0) 编辑
摘要: Structs 类型定义(type)相当于一种别名 将struct定义为一种类型Car NewCar函数return &Car{},返回指针 // car.go package elon // Car implements a remote controlled car. type Car stru 阅读全文
posted @ 2023-02-19 15:41 roadwide 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 不需要手动break default是找不到case时执行 可以对多个case执行同样的操作 operatingSystem := "windows" switch operatingSystem { case "windows", "linux": // do something if the o 阅读全文
posted @ 2023-02-19 15:28 roadwide 阅读(36) 评论(0) 推荐(0) 编辑