Code_026_go_antic_package Project Main.go<pre name= "code" class= "plain" >package mainimport ("Container/list" "FMT" "Math/rand"//NOTE 2: Random number of packages "sync"//NOTE 1: Asynchronous task Package "time") type INFO struct {lock sync. Mutex//NOTE 1: Asynchronous lock Name string time Int64}var List *list. List = list. New ()//NOTE 3: Initialize the list variable func main () {var info info go func () {for i: = 0; i < 5; i++ {time. Sleep (time. Duration (1E9 * Int64 (RAND). INTN (5)))//NOTE 2: Random number Rand. INTN (5) <---> 1e9 is scientific notation, 1 * 10 of 9 Info.lock.Lock ()//NOTE 1: Locked info.name = fmt. Sprint ("Name", I)///NOTE: Sprint formats its parameters in the default format, concatenates all output and returns a string. If two adjacent parameters are not strings, a space is added between their outputs Info.time = time. Now (). Unix () + 3 Info.lock.Unlock ()//NOTE 1: Unlock list.pushback (Info)//comment 3:list expression call}} () go Getgoods () Select {}}func getgoods () {f or {time. Sleep (1e8) for List.len () > 0 {//Memo 3:list object using N, T: = List.remove (List.front ()). ( INFO). Name ()//Memo 3:list the use and value of the object. The magic of (type) Now: = time. Now (). Unix ()//Note 4: Gets the current date after the converted timestamp if T-now <= 0 {fmt. Println (N, T, now) continue} time. Sleep (time. Duration ((t-now) * 1e9)) fmt. Println (N, T, Now)}}}func (i INFO) name (string, Int64) {return i.name, i.time}
Type queries for interfaces in go: COMMA-OK assertions and switch tests