摘要: 可以使用Go实现自动化测试,EdgeX中也使用了大量的test代码 1、在工程里新建一个Test目录,创建一个文件testtestify_test.go,必须以_test结尾,代码如下 package Test import ( "fmt" "testing" "github.com/stretch 阅读全文
posted @ 2021-07-25 21:30 zhaogaojian 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 1、代码,可以通过Context关闭任务 package main import ( "context" "fmt" "time" ) func main() { ctx1, cancel1 := context.WithCancel(context.Background()) ctx2, canc 阅读全文
posted @ 2021-07-25 18:04 zhaogaojian 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 1、代码,实现向管道里写100个数,再读出 package main func readCh(ch1 chan int){ for n:=0;n<100;n++{ m:=<- ch1 println(m) } } func writeCh(ch1 chan int) { for n:=0;n<100 阅读全文
posted @ 2021-07-25 16:40 zhaogaojian 阅读(133) 评论(0) 推荐(0) 编辑
摘要: goroutine 是轻量级线程,goroutine 的调度是由 Golang 运行时进行管理的。 goroutine 语法格式: 1、代码 package main import ( "fmt" "time" ) func say(s string) { for i := 0; i < 5; i+ 阅读全文
posted @ 2021-07-25 16:12 zhaogaojian 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 1、代码 // json.go package main import ( "encoding/json" "fmt" "os" ) type Student struct { Name string Age int } type Class struct { Students []Student 阅读全文
posted @ 2021-07-25 10:59 zhaogaojian 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 1、代码 //project main.go package main import ( "fmt" "strings" serial "github.com/tarm/goserial" ) const MAXRWLEN = 8000 func main() { cfg := &serial.Co 阅读全文
posted @ 2021-07-25 00:17 zhaogaojian 阅读(1626) 评论(0) 推荐(0) 编辑