ZhangZhihui's Blog  
上一页 1 ··· 96 97 98 99 100 101 102 103 104 ··· 116 下一页

2023年10月8日

摘要: Problem: You want to make arrays and slices safe for concurrent use by multiple goroutines. Solution: Use a mutex from the sync library to safeguard t 阅读全文
posted @ 2023-10-08 10:19 ZhangZhihuiAAA 阅读(27) 评论(0) 推荐(0)

2023年10月7日

摘要: To take out the first element of the slice: numbers := []int{3, 14, 159, 26, 53, 58} numbers = numbers[1:] // remove element 0 To take out the last el 阅读全文
posted @ 2023-10-07 22:58 ZhangZhihuiAAA 阅读(17) 评论(0) 推荐(0)
 
摘要: There is no built-in function for insertion, but you can still use append for the task. Let’s say you want to insert the number 1000 between elements 阅读全文
posted @ 2023-10-07 22:50 ZhangZhihuiAAA 阅读(35) 评论(0) 推荐(0)
 
摘要: Problem: You want to define metadata to describe the struct fields. Solution: Use struct tags to define metadata and the reflect package to access the 阅读全文
posted @ 2023-10-07 22:32 ZhangZhihuiAAA 阅读(24) 评论(0) 推荐(0)
 
摘要: Problem: You want to create an instance of a struct. Solution: Create a struct instance directly using the name of the struct, or a pointer to a struc 阅读全文
posted @ 2023-10-07 11:28 ZhangZhihuiAAA 阅读(17) 评论(0) 推荐(0)

2023年10月6日

摘要: func main() { str := "4:31am +0800 on Oct 1, 2021" layout := "3:04pm -0700 on Jan 2, 2006" t, err := time.Parse(layout, str) if err != nil { log.Print 阅读全文
posted @ 2023-10-06 13:13 ZhangZhihuiAAA 阅读(13) 评论(0) 推荐(0)
 
摘要: func main() { t := time.Now() fmt.Println(t.Format("3:04PM")) fmt.Println(t.Format("Jan 02, 2006")) } When you run this you should see something like: 阅读全文
posted @ 2023-10-06 12:54 ZhangZhihuiAAA 阅读(17) 评论(0) 推荐(0)
 
摘要: Problem: You want to measure the lapsed time and make sure that it is accurate. Solution: Use the monotonic clock in the Time struct to find the lapse 阅读全文
posted @ 2023-10-06 12:22 ZhangZhihuiAAA 阅读(23) 评论(0) 推荐(0)

2023年10月5日

摘要: Problem: You want to specify a duration of time. Solution: Use the Duration type to represent a span of time. The main representation for a span of ti 阅读全文
posted @ 2023-10-05 18:25 ZhangZhihuiAAA 阅读(23) 评论(0) 推荐(0)
 
摘要: Problem: You want to include the time zone information in a Time struct. Solution: The Time struct includes a Location , which is the representation o 阅读全文
posted @ 2023-10-05 16:12 ZhangZhihuiAAA 阅读(22) 评论(0) 推荐(0)
上一页 1 ··· 96 97 98 99 100 101 102 103 104 ··· 116 下一页