环境搭建
安装golang
- 从golang中文官网下载go语言安装包
- 下载完成后解压配置环境变量
命令行输入go version
安装goland
- 从goland官网下载goland安装包
- 双击后正常安装就可
创建项目
初始化项目
- 打开goland,创建go项目,取名为leafBot-plugin
- 初始化项目
go mod init github.com/huoxue1/fan
- 安装leafbot依赖
go get github.com/huoxue1/leafbot
- 跟项目下创建main.go文件
编写main.go文件,初始化leafBot
- 在main.go中修改package为main
- 创建main方法,添加如下代码
// main方法,项目运行起点
func main() {
// 创建一个cqhttp的driver
driver := cqhttp_default_driver.NewDriver()
// 为leafBot加载该驱动
leafbot.LoadDriver(driver)
// 初始化leafBot
leafbot.InitBots()
// 运行cqhttp驱动
driver.Run()
}
- 一般main.go会自动导入如下依赖
import (
// leafbot核心依赖
"github.com/huoxue1/leafbot"
// leafbot的cqhttp与leafbot直接结合所用的依赖
"github.com/huoxue1/leafbot/cqhttp_default_driver"
)
- main.go最终结果为
package main
import (
"github.com/huoxue1/leafbot"
"github.com/huoxue1/leafbot/cqhttp_default_driver"
)
func main() {
driver := cqhttp_default_driver.NewDriver()
leafbot.