随笔分类 -  Go

摘要:package main import ( "fmt" "github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger" "github.com/edgexfoundry/go-mod-core-contracts/v2/models 阅读全文
posted @ 2021-08-12 20:31 zhaogaojian 阅读(150) 评论(0) 推荐(0) 编辑
摘要:什么是Unix时间戳(Unix timestamp): Unix时间戳(Unix timestamp),或称Unix时间(Unix time)、POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数。Unix时间戳不仅 阅读全文
posted @ 2021-08-12 17:02 zhaogaojian 阅读(248) 评论(0) 推荐(0) 编辑
摘要:EdgeX支持多种平台下测试CPU占用率,下面是Linux核心代码 1、代码 package main import ( "bitbucket.org/bertimus9/systemstat" "fmt" "math" "time" ) var lastSample CpuUsage var us 阅读全文
posted @ 2021-08-12 16:41 zhaogaojian 阅读(523) 评论(0) 推荐(0) 编辑
摘要:可以使用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 阅读(70) 评论(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 阅读(132) 评论(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 阅读(63) 评论(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 阅读(1542) 评论(0) 推荐(0) 编辑
摘要:1、代码 package main import ( "bufio" "fmt" "net" "os" "strings" ) func main() { ClientBase() } func ClientBase() { //open connection: conn, err := net.D 阅读全文
posted @ 2021-07-24 22:46 zhaogaojian 阅读(106) 评论(0) 推荐(0) 编辑
摘要:1、代码 package main import ( "fmt" "net" ) func main() { fmt.Println("Starting the server ...") // 创建 listener listener, err := net.Listen("tcp", "local 阅读全文
posted @ 2021-07-24 22:40 zhaogaojian 阅读(83) 评论(0) 推荐(0) 编辑
摘要:一、 VSCode 开发环境 虚拟机总莫名奇妙卡着,改用windows环境,用vscode打开刚才的test.go文件,会自动下载想关插件, 1、选择目录,自动生成配置文件,vscode可以选择部分代码片段执行,也可以直接执行。 选择代码片段运行时会生成一个新的go文件 2、 调试时增加调试配置文件 阅读全文
posted @ 2021-07-24 18:41 zhaogaojian 阅读(77) 评论(0) 推荐(0) 编辑
摘要:为了理解EdgeX代码,学习了下Go语言基础,学习过程记录一下。 1、系统使用的unbuntu20.04 如果使用apt-get install golang安装的是1.13版本的 snap install go # version 1.16.5, orapt install golang-go # 阅读全文
posted @ 2021-07-24 17:30 zhaogaojian 阅读(394) 评论(0) 推荐(0) 编辑