上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 44 下一页
摘要: map和切片结合使用 package main import( "fmt" "math/rand" "time" ) func testSliceMap(){ rand.Seed(time.Now().UnixNano()) var s []map[string]int s = make([]map 阅读全文
posted @ 2022-03-10 22:02 ty1539 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 不带缓存区的, 必需要goroutine等待着从队列中取,才能放入无缓存的队列中 package main import ( "fmt" "time" ) func produce(c chan int) { fmt.Println("produce start") time.Sleep(time. 阅读全文
posted @ 2022-03-10 21:50 ty1539 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 用死循环的方式从ch中获取数据, 但是得自己判断ch是否已经取空了 点击查看代码 package main import ( "fmt" ) func producer(chnl chan int) { for i := 0; i < 10; i++ { chnl <- i } defer clos 阅读全文
posted @ 2022-03-10 21:49 ty1539 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 package main import ( "fmt" "time" ) func producer(chnl chan int) { for i := 0; i < 10; i++ { chnl <- i time.Sleep(time.Second) } close(chnl) } 阅读全文
posted @ 2022-03-10 21:42 ty1539 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 package main import ( "fmt" "time" ) func write(ch chan int) { for i := 0; i < 5; i++ { ch <- i fmt.Println("successfully wrote", i, "to ch") } 阅读全文
posted @ 2022-03-10 21:33 ty1539 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 利用goroutine等待的取出元素的时机,没有元素取出来,就一直阻塞,等待goroutine协程完成,取出队列中的元素,该进程才结束 点击查看代码 package main import ( "fmt" "time" ) func hello(c chan bool) { time.Sleep(5 阅读全文
posted @ 2022-03-10 21:14 ty1539 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 package main import ( "fmt" "time" ) func numbers() { for i := 1; i <= 5; i++ { time.Sleep(250 * time.Millisecond) fmt.Printf("%d ", i) } } fun 阅读全文
posted @ 2022-03-10 21:01 ty1539 阅读(17) 评论(0) 推荐(0) 编辑
摘要: https://blog.csdn.net/skh2015java/article/details/83583516 点击查看代码 //http请求 func httpHandle(method, urlVal,data string) { client := &http.Client{} var 阅读全文
posted @ 2022-03-07 23:56 ty1539 阅读(1439) 评论(0) 推荐(0) 编辑
摘要: https://blog.csdn.net/qq_21852449/article/details/88093941 点击查看代码 package hsession import ( "crypto/rand" "encoding/base64" "io" "net/http" "net/url" 阅读全文
posted @ 2022-03-07 23:47 ty1539 阅读(393) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 package main import "fmt" type Animal interface{ Talk() Eat() Name() string } type Dog struct{} func (d *Dog) Talk(){ fmt.Println("汪汪汪") } func 阅读全文
posted @ 2022-03-07 23:44 ty1539 阅读(33) 评论(0) 推荐(0) 编辑
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 44 下一页