学习目标:
实现go语言下goframe框架与EMQX搭建的MQTT Server的连接、订阅、推送、断开等操作
开发工具:
Win10 + goland
正式操作:
1、goLand下创建新功能 goframeMqttTestProject,开始安装gf框架(golang版本 >= 1.11)
go get -u -v github.com/gogf/gf
go mod init
go mod edit -require github.com/gogf/gf@latest
go mod tidy
2、创建main.go文件,添加如下hello代码
package main
import (
"fmt"
"github.com/gogf/gf"
)
func main() {
fmt.Println("hello world!")
// 打印GF版本
fmt.Println(gf.VERSION)
}
3、运行成功,结果如下。
4、开始搭建一个Web项目测试
package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler(&