1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-07 20:45:53 +08:00

Merge pull request #572 from Ink-33/dev

fix golint warning
This commit is contained in:
Mrs4s 2021-01-18 22:27:01 +08:00 committed by GitHub
commit 63d26dfdb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 514 additions and 282 deletions

View File

@ -730,10 +730,10 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
} }
func (bot *CQBot) CQGetImage(file string) MSG { func (bot *CQBot) CQGetImage(file string) MSG {
if !global.PathExists(path.Join(global.IMAGE_PATH, file)) { if !global.PathExists(path.Join(global.ImagePath, file)) {
return Failed(100) return Failed(100)
} }
if b, err := ioutil.ReadFile(path.Join(global.IMAGE_PATH, file)); err == nil { if b, err := ioutil.ReadFile(path.Join(global.ImagePath, file)); err == nil {
r := binary.NewReader(b) r := binary.NewReader(b)
r.ReadBytes(16) r.ReadBytes(16)
msg := MSG{ msg := MSG{
@ -741,7 +741,7 @@ func (bot *CQBot) CQGetImage(file string) MSG {
"filename": r.ReadString(), "filename": r.ReadString(),
"url": r.ReadString(), "url": r.ReadString(),
} }
local := path.Join(global.CACHE_PATH, file+"."+path.Ext(msg["filename"].(string))) local := path.Join(global.CachePath, file+"."+path.Ext(msg["filename"].(string)))
if !global.PathExists(local) { if !global.PathExists(local) {
if data, err := global.GetBytes(msg["url"].(string)); err == nil { if data, err := global.GetBytes(msg["url"].(string)); err == nil {
_ = ioutil.WriteFile(local, data, 0644) _ = ioutil.WriteFile(local, data, 0644)
@ -756,7 +756,7 @@ func (bot *CQBot) CQGetImage(file string) MSG {
func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG { func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG {
hash := md5.Sum([]byte(url)) hash := md5.Sum([]byte(url))
file := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache") file := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
if global.PathExists(file) { if global.PathExists(file) {
if err := os.Remove(file); err != nil { if err := os.Remove(file); err != nil {
log.Warnf("删除缓存文件 %v 时出现错误: %v", file, err) log.Warnf("删除缓存文件 %v 时出现错误: %v", file, err)
@ -867,7 +867,7 @@ func (bot *CQBot) CQReloadEventFilter() MSG {
func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG { func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
if g := bot.Client.FindGroup(groupId); g != nil { if g := bot.Client.FindGroup(groupId); g != nil {
img, err := global.FindFile(file, cache, global.IMAGE_PATH) img, err := global.FindFile(file, cache, global.ImagePath)
if err != nil { if err != nil {
log.Warnf("set group portrait error: %v", err) log.Warnf("set group portrait error: %v", err)
return Failed(100, "LOAD_FILE_ERROR", err.Error()) return Failed(100, "LOAD_FILE_ERROR", err.Error())

View File

@ -5,7 +5,6 @@ import (
"encoding/gob" "encoding/gob"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/Mrs4s/MiraiGo/utils"
"hash/crc32" "hash/crc32"
"io" "io"
"os" "os"
@ -14,6 +13,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
@ -41,7 +42,7 @@ type MSG map[string]interface{}
var ForceFragmented = false var ForceFragmented = false
func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot { func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
bot := &CQBot{ bot := &CQBot{
Client: cli, Client: cli,
} }
@ -136,7 +137,7 @@ func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message
} }
defer video.Close() defer video.Close()
hash, _ := utils.ComputeMd5AndLength(io.MultiReader(video, v.thumb)) hash, _ := utils.ComputeMd5AndLength(io.MultiReader(video, v.thumb))
cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache") cacheFile := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
_, _ = video.Seek(0, io.SeekStart) _, _ = video.Seek(0, io.SeekStart)
_, _ = v.thumb.Seek(0, io.SeekStart) _, _ = v.thumb.Seek(0, io.SeekStart)
return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile) return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile)
@ -456,7 +457,7 @@ func (bot *CQBot) Release() {
} }
func (bot *CQBot) dispatchEventMessage(m MSG) { func (bot *CQBot) dispatchEventMessage(m MSG) {
if global.EventFilter != nil && global.EventFilter.Eval(global.MSG(m)) == false { if global.EventFilter != nil && !global.EventFilter.Eval(global.MSG(m)) {
log.Debug("Event filtered!") log.Debug("Event filtered!")
return return
} }

View File

@ -132,7 +132,7 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
}) })
} }
for _, elem := range e { for _, elem := range e {
m := MSG{} var m MSG
switch o := elem.(type) { switch o := elem.(type) {
case *message.TextElement: case *message.TextElement:
m = MSG{ m = MSG{
@ -369,7 +369,7 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
saveTempText := func() { saveTempText := func() {
if len(tempText) != 0 { if len(tempText) != 0 {
if SplitUrl { if SplitUrl {
for _, t := range global.SplitUrl(CQCodeUnescapeValue(string(tempText))) { for _, t := range global.SplitURL(CQCodeUnescapeValue(string(tempText))) {
r = append(r, message.NewText(t)) r = append(r, message.NewText(t))
} }
} else { } else {
@ -548,7 +548,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
case "text": case "text":
if SplitUrl { if SplitUrl {
var ret []message.IMessageElement var ret []message.IMessageElement
for _, text := range global.SplitUrl(d["text"]) { for _, text := range global.SplitURL(d["text"]) {
ret = append(ret, message.NewText(text)) ret = append(ret, message.NewText(text))
} }
return ret, nil return ret, nil
@ -619,9 +619,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
return &message.VoiceElement{Data: data}, nil return &message.VoiceElement{Data: data}, nil
case "record": case "record":
f := d["file"] f := d["file"]
data, err := global.FindFile(f, d["cache"], global.VOICE_PATH) data, err := global.FindFile(f, d["cache"], global.VoicePath)
if err == global.ErrSyntax { if err == global.ErrSyntax {
data, err = global.FindFile(f, d["cache"], global.VOICE_PATH_OLD) data, err = global.FindFile(f, d["cache"], global.VoicePathOld)
} }
if err != nil { if err != nil {
return nil, err return nil, err
@ -797,7 +797,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
} }
var data []byte var data []byte
if cover, ok := d["cover"]; ok { if cover, ok := d["cover"]; ok {
data, _ = global.FindFile(cover, cache, global.IMAGE_PATH) data, _ = global.FindFile(cover, cache, global.ImagePath)
} else { } else {
_ = global.ExtractCover(v.File, v.File+".jpg") _ = global.ExtractCover(v.File, v.File+".jpg")
data, _ = ioutil.ReadFile(v.File + ".jpg") data, _ = ioutil.ReadFile(v.File + ".jpg")
@ -811,10 +811,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
} }
var header = make([]byte, 4) var header = make([]byte, 4)
_, err = video.Read(header) _, err = video.Read(header)
if err != nil {
return nil, err
}
if !bytes.Equal(header, []byte{0x66, 0x74, 0x79, 0x70}) { // check file header ftyp if !bytes.Equal(header, []byte{0x66, 0x74, 0x79, 0x70}) { // check file header ftyp
_, _ = video.Seek(0, io.SeekStart) _, _ = video.Seek(0, io.SeekStart)
hash, _ := utils.ComputeMd5AndLength(video) hash, _ := utils.ComputeMd5AndLength(video)
cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".mp4") cacheFile := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".mp4")
if global.PathExists(cacheFile) && cache == "1" { if global.PathExists(cacheFile) && cache == "1" {
goto ok goto ok
} }
@ -876,7 +879,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
cache = "1" cache = "1"
} }
hash := md5.Sum([]byte(f)) hash := md5.Sum([]byte(f))
cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache") cacheFile := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
var maxSize = func() int64 { var maxSize = func() int64 {
if video { if video {
return maxVideoSize return maxVideoSize
@ -925,9 +928,9 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
} }
return &LocalImageElement{File: fu.Path}, nil return &LocalImageElement{File: fu.Path}, nil
} }
rawPath := path.Join(global.IMAGE_PATH, f) rawPath := path.Join(global.ImagePath, f)
if video { if video {
rawPath = path.Join(global.VIDEO_PATH, f) rawPath = path.Join(global.VideoPath, f)
if !global.PathExists(rawPath) { if !global.PathExists(rawPath) {
return nil, errors.New("invalid video") return nil, errors.New("invalid video")
} }
@ -953,8 +956,8 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
} }
return &LocalImageElement{Stream: bytes.NewReader(b)}, nil return &LocalImageElement{Stream: bytes.NewReader(b)}, nil
} }
if !global.PathExists(rawPath) && global.PathExists(path.Join(global.IMAGE_PATH_OLD, f)) { if !global.PathExists(rawPath) && global.PathExists(path.Join(global.ImagePathOld, f)) {
rawPath = path.Join(global.IMAGE_PATH_OLD, f) rawPath = path.Join(global.ImagePathOld, f)
} }
if !global.PathExists(rawPath) && global.PathExists(rawPath+".cqimg") { if !global.PathExists(rawPath) && global.PathExists(rawPath+".cqimg") {
rawPath += ".cqimg" rawPath += ".cqimg"
@ -1032,7 +1035,7 @@ func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon
xml := "" xml := ""
var suf message.IMessageElement var suf message.IMessageElement
if i, ok := elem.(*LocalImageElement); ok { if i, ok := elem.(*LocalImageElement); ok {
if group == false { if !group {
gm, err := bot.UploadLocalImageAsPrivate(1, i) gm, err := bot.UploadLocalImageAsPrivate(1, i)
if err != nil { if err != nil {
log.Warnf("警告: 好友消息 %v 消息图片上传失败: %v", 1, err) log.Warnf("警告: 好友消息 %v 消息图片上传失败: %v", 1, err)

View File

@ -17,15 +17,17 @@ import (
var format = "string" var format = "string"
//SetMessageFormat 设置消息上报格式默认为string
func SetMessageFormat(f string) { func SetMessageFormat(f string) {
format = f format = f
} }
func ToFormattedMessage(e []message.IMessageElement, code int64, raw ...bool) (r interface{}) { //ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式
func ToFormattedMessage(e []message.IMessageElement, id int64, raw ...bool) (r interface{}) {
if format == "string" { if format == "string" {
r = ToStringMessage(e, code, raw...) r = ToStringMessage(e, id, raw...)
} else if format == "array" { } else if format == "array" {
r = ToArrayMessage(e, code, raw...) r = ToArrayMessage(e, id, raw...)
} }
return return
} }
@ -499,8 +501,8 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
switch i := elem.(type) { switch i := elem.(type) {
case *message.ImageElement: case *message.ImageElement:
filename := hex.EncodeToString(i.Md5) + ".image" filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) { if !global.PathExists(path.Join(global.ImagePath, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) { _ = ioutil.WriteFile(path.Join(global.ImagePath, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5) w.Write(i.Md5)
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))
w.WriteString(i.Filename) w.WriteString(i.Filename)
@ -510,8 +512,8 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
i.Filename = filename i.Filename = filename
case *message.GroupImageElement: case *message.GroupImageElement:
filename := hex.EncodeToString(i.Md5) + ".image" filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) { if !global.PathExists(path.Join(global.ImagePath, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) { _ = ioutil.WriteFile(path.Join(global.ImagePath, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5) w.Write(i.Md5)
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))
w.WriteString(filename) w.WriteString(filename)
@ -520,8 +522,8 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
} }
case *message.FriendImageElement: case *message.FriendImageElement:
filename := hex.EncodeToString(i.Md5) + ".image" filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) { if !global.PathExists(path.Join(global.ImagePath, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) { _ = ioutil.WriteFile(path.Join(global.ImagePath, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5) w.Write(i.Md5)
w.WriteUInt32(uint32(0)) // 发送时会调用url, 大概没事 w.WriteUInt32(uint32(0)) // 发送时会调用url, 大概没事
w.WriteString(filename) w.WriteString(filename)
@ -530,8 +532,8 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
} }
case *message.GroupFlashImgElement: case *message.GroupFlashImgElement:
filename := hex.EncodeToString(i.Md5) + ".image" filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) { if !global.PathExists(path.Join(global.ImagePath, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) { _ = ioutil.WriteFile(path.Join(global.ImagePath, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5) w.Write(i.Md5)
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))
w.WriteString(i.Filename) w.WriteString(i.Filename)
@ -541,8 +543,8 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
i.Filename = filename i.Filename = filename
case *message.FriendFlashImgElement: case *message.FriendFlashImgElement:
filename := hex.EncodeToString(i.Md5) + ".image" filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) { if !global.PathExists(path.Join(global.ImagePath, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) { _ = ioutil.WriteFile(path.Join(global.ImagePath, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5) w.Write(i.Md5)
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))
w.WriteString(i.Filename) w.WriteString(i.Filename)
@ -553,18 +555,18 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
case *message.VoiceElement: case *message.VoiceElement:
i.Name = strings.ReplaceAll(i.Name, "{", "") i.Name = strings.ReplaceAll(i.Name, "{", "")
i.Name = strings.ReplaceAll(i.Name, "}", "") i.Name = strings.ReplaceAll(i.Name, "}", "")
if !global.PathExists(path.Join(global.VOICE_PATH, i.Name)) { if !global.PathExists(path.Join(global.VoicePath, i.Name)) {
b, err := global.GetBytes(i.Url) b, err := global.GetBytes(i.Url)
if err != nil { if err != nil {
log.Warnf("语音文件 %v 下载失败: %v", i.Name, err) log.Warnf("语音文件 %v 下载失败: %v", i.Name, err)
continue continue
} }
_ = ioutil.WriteFile(path.Join(global.VOICE_PATH, i.Name), b, 0644) _ = ioutil.WriteFile(path.Join(global.VoicePath, i.Name), b, 0644)
} }
case *message.ShortVideoElement: case *message.ShortVideoElement:
filename := hex.EncodeToString(i.Md5) + ".video" filename := hex.EncodeToString(i.Md5) + ".video"
if !global.PathExists(path.Join(global.VIDEO_PATH, filename)) { if !global.PathExists(path.Join(global.VideoPath, filename)) {
_ = ioutil.WriteFile(path.Join(global.VIDEO_PATH, filename), binary.NewWriterF(func(w *binary.Writer) { _ = ioutil.WriteFile(path.Join(global.VideoPath, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5) w.Write(i.Md5)
w.Write(i.ThumbMd5) w.Write(i.ThumbMd5)
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))

View File

@ -4,15 +4,17 @@ import (
"crypto/md5" "crypto/md5"
"errors" "errors"
"fmt" "fmt"
"github.com/Mrs4s/go-cqhttp/global/codec"
log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os/exec" "os/exec"
"path" "path"
"github.com/Mrs4s/go-cqhttp/global/codec"
log "github.com/sirupsen/logrus"
) )
var useSilkCodec = true var useSilkCodec = true
//InitCodec 初始化Silk编码器
func InitCodec() { func InitCodec() {
log.Info("正在加载silk编码器...") log.Info("正在加载silk编码器...")
err := codec.Init() err := codec.Init()
@ -22,12 +24,16 @@ func InitCodec() {
} }
} }
//EncoderSilk 将音频编码为Silk
func EncoderSilk(data []byte) ([]byte, error) { func EncoderSilk(data []byte) ([]byte, error) {
if useSilkCodec == false { if !useSilkCodec {
return nil, errors.New("no silk encoder") return nil, errors.New("no silk encoder")
} }
h := md5.New() h := md5.New()
h.Write(data) _, err := h.Write(data)
if err != nil {
return nil, err
}
tempName := fmt.Sprintf("%x", h.Sum(nil)) tempName := fmt.Sprintf("%x", h.Sum(nil))
if silkPath := path.Join("data/cache", tempName+".silk"); PathExists(silkPath) { if silkPath := path.Join("data/cache", tempName+".silk"); PathExists(silkPath) {
return ioutil.ReadFile(silkPath) return ioutil.ReadFile(silkPath)
@ -39,6 +45,7 @@ func EncoderSilk(data []byte) ([]byte, error) {
return slk, nil return slk, nil
} }
//EncodeMP4 将给定视频文件编码为MP4
func EncodeMP4(src string, dst string) error { // -y 覆盖文件 func EncodeMP4(src string, dst string) error { // -y 覆盖文件
cmd1 := exec.Command("ffmpeg", "-i", src, "-y", "-c", "copy", "-map", "0", dst) cmd1 := exec.Command("ffmpeg", "-i", src, "-y", "-c", "copy", "-map", "0", dst)
err := cmd1.Run() err := cmd1.Run()
@ -49,7 +56,8 @@ func EncodeMP4(src string, dst string) error { // -y 覆盖文件
return err return err
} }
func ExtractCover(src string, dst string) error { //ExtractCover 获取给定视频文件的Cover
cmd := exec.Command("ffmpeg", "-i", src, "-y", "-r", "1", "-f", "image2", dst) func ExtractCover(src string, target string) error {
cmd := exec.Command("ffmpeg", "-i", src, "-y", "-r", "1", "-f", "image2", target)
return cmd.Run() return cmd.Run()
} }

View File

@ -40,6 +40,7 @@ func getEncoderFilePath() string {
return encoderFile return encoderFile
} }
//Init 下载Silk编码器
func Init() error { func Init() error {
if !fileExist(silkCachePath) { if !fileExist(silkCachePath) {
_ = os.MkdirAll(silkCachePath, os.ModePerm) _ = os.MkdirAll(silkCachePath, os.ModePerm)
@ -56,6 +57,7 @@ func Init() error {
return nil return nil
} }
//EncodeToSilk 将音频编码为Silk
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) { func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
// 1. 写入缓存文件 // 1. 写入缓存文件
rawPath := path.Join(silkCachePath, tempName+".wav") rawPath := path.Join(silkCachePath, tempName+".wav")
@ -79,7 +81,7 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error)
if err = cmd.Run(); err != nil { if err = cmd.Run(); err != nil {
return nil, err return nil, err
} }
if useCache == false { if !useCache {
defer os.Remove(silkPath) defer os.Remove(silkPath)
} }
return ioutil.ReadFile(silkPath) return ioutil.ReadFile(silkPath)

View File

@ -4,10 +4,12 @@ package codec
import "errors" import "errors"
//Init 下载silk编码器
func Init() error { func Init() error {
return errors.New("Unsupport arch now") return errors.New("Unsupport arch now")
} }
//EncodeToSilk 将音频编码为Silk
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) { func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
return nil, errors.New("Unsupport arch now") return nil, errors.New("Unsupport arch now")
} }

View File

@ -4,10 +4,12 @@ package codec
import "errors" import "errors"
//Init 下载silk编码器
func Init() error { func Init() error {
return errors.New("not support now") return errors.New("not support now")
} }
//EncodeToSilk 将音频编码为Silk
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) { func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
return nil, errors.New("not support now") return nil, errors.New("not support now")
} }

View File

@ -12,6 +12,7 @@ import (
var json = jsoniter.ConfigCompatibleWithStandardLibrary var json = jsoniter.ConfigCompatibleWithStandardLibrary
//DefaultConfigWithComments 为go-cqhttp的默认配置文件
var DefaultConfigWithComments = ` var DefaultConfigWithComments = `
/* /*
go-cqhttp 默认配置文件 go-cqhttp 默认配置文件
@ -134,7 +135,8 @@ var DefaultConfigWithComments = `
} }
` `
type JsonConfig struct { //JSONConfig Config对应的结构体
type JSONConfig struct {
Uin int64 `json:"uin"` Uin int64 `json:"uin"`
Password string `json:"password"` Password string `json:"password"`
EncryptPassword bool `json:"encrypt_password"` EncryptPassword bool `json:"encrypt_password"`
@ -153,39 +155,41 @@ type JsonConfig struct {
} `json:"_rate_limit"` } `json:"_rate_limit"`
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"` IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
ForceFragmented bool `json:"force_fragmented"` ForceFragmented bool `json:"force_fragmented"`
FixUrl bool `json:"fix_url"` FixURL bool `json:"fix_url"`
ProxyRewrite string `json:"proxy_rewrite"` ProxyRewrite string `json:"proxy_rewrite"`
HeartbeatInterval time.Duration `json:"heartbeat_interval"` HeartbeatInterval time.Duration `json:"heartbeat_interval"`
HttpConfig *GoCQHttpConfig `json:"http_config"` HTTPConfig *GoCQHTTPConfig `json:"http_config"`
WSConfig *GoCQWebsocketConfig `json:"ws_config"` WSConfig *GoCQWebSocketConfig `json:"ws_config"`
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` ReverseServers []*GoCQReverseWebSocketConfig `json:"ws_reverse_servers"`
PostMessageFormat string `json:"post_message_format"` PostMessageFormat string `json:"post_message_format"`
UseSSOAddress bool `json:"use_sso_address"` UseSSOAddress bool `json:"use_sso_address"`
Debug bool `json:"debug"` Debug bool `json:"debug"`
LogLevel string `json:"log_level"` LogLevel string `json:"log_level"`
WebUi *GoCqWebUi `json:"web_ui"` WebUI *GoCQWebUI `json:"web_ui"`
} }
type CQHttpApiConfig struct { //CQHTTPAPIConfig HTTPAPI对应的Config结构体
type CQHTTPAPIConfig struct {
Host string `json:"host"` Host string `json:"host"`
Port uint16 `json:"port"` Port uint16 `json:"port"`
UseHttp bool `json:"use_http"` UseHTTP bool `json:"use_http"`
WSHost string `json:"ws_host"` WSHost string `json:"ws_host"`
WSPort uint16 `json:"ws_port"` WSPort uint16 `json:"ws_port"`
UseWS bool `json:"use_ws"` UseWS bool `json:"use_ws"`
WSReverseUrl string `json:"ws_reverse_url"` WSReverseURL string `json:"ws_reverse_url"`
WSReverseApiUrl string `json:"ws_reverse_api_url"` WSReverseAPIURL string `json:"ws_reverse_api_url"`
WSReverseEventUrl string `json:"ws_reverse_event_url"` WSReverseEventURL string `json:"ws_reverse_event_url"`
WSReverseReconnectInterval uint16 `json:"ws_reverse_reconnect_interval"` WSReverseReconnectInterval uint16 `json:"ws_reverse_reconnect_interval"`
WSReverseReconnectOnCode1000 bool `json:"ws_reverse_reconnect_on_code_1000"` WSReverseReconnectOnCode1000 bool `json:"ws_reverse_reconnect_on_code_1000"`
UseWsReverse bool `json:"use_ws_reverse"` UseWsReverse bool `json:"use_ws_reverse"`
PostUrl string `json:"post_url"` PostURL string `json:"post_url"`
AccessToken string `json:"access_token"` AccessToken string `json:"access_token"`
Secret string `json:"secret"` Secret string `json:"secret"`
PostMessageFormat string `json:"post_message_format"` PostMessageFormat string `json:"post_message_format"`
} }
type GoCQHttpConfig struct { //GoCQHTTPConfig 正向HTTP对应config结构体
type GoCQHTTPConfig struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
Host string `json:"host"` Host string `json:"host"`
Port uint16 `json:"port"` Port uint16 `json:"port"`
@ -193,29 +197,33 @@ type GoCQHttpConfig struct {
PostUrls map[string]string `json:"post_urls"` PostUrls map[string]string `json:"post_urls"`
} }
type GoCQWebsocketConfig struct { //GoCQWebSocketConfig 正向WebSocket对应Config结构体
type GoCQWebSocketConfig struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
Host string `json:"host"` Host string `json:"host"`
Port uint16 `json:"port"` Port uint16 `json:"port"`
} }
type GoCQReverseWebsocketConfig struct { //GoCQReverseWebSocketConfig 反向WebSocket对应Config结构体
type GoCQReverseWebSocketConfig struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
ReverseUrl string `json:"reverse_url"` ReverseURL string `json:"reverse_url"`
ReverseApiUrl string `json:"reverse_api_url"` ReverseAPIURL string `json:"reverse_api_url"`
ReverseEventUrl string `json:"reverse_event_url"` ReverseEventURL string `json:"reverse_event_url"`
ReverseReconnectInterval uint16 `json:"reverse_reconnect_interval"` ReverseReconnectInterval uint16 `json:"reverse_reconnect_interval"`
} }
type GoCqWebUi struct { //GoCQWebUI WebUI对应Config结构体
type GoCQWebUI struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
Host string `json:"host"` Host string `json:"host"`
WebUiPort uint64 `json:"web_ui_port"` WebUIPort uint64 `json:"web_ui_port"`
WebInput bool `json:"web_input"` WebInput bool `json:"web_input"`
} }
func DefaultConfig() *JsonConfig { //DefaultConfig 返回一份默认配置对应结构体
return &JsonConfig{ func DefaultConfig() *JSONConfig {
return &JSONConfig{
EnableDB: true, EnableDB: true,
ReLogin: struct { ReLogin: struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
@ -237,42 +245,43 @@ func DefaultConfig() *JsonConfig {
}, },
PostMessageFormat: "string", PostMessageFormat: "string",
ForceFragmented: false, ForceFragmented: false,
HttpConfig: &GoCQHttpConfig{ HTTPConfig: &GoCQHTTPConfig{
Enabled: true, Enabled: true,
Host: "0.0.0.0", Host: "0.0.0.0",
Port: 5700, Port: 5700,
PostUrls: map[string]string{}, PostUrls: map[string]string{},
}, },
WSConfig: &GoCQWebsocketConfig{ WSConfig: &GoCQWebSocketConfig{
Enabled: true, Enabled: true,
Host: "0.0.0.0", Host: "0.0.0.0",
Port: 6700, Port: 6700,
}, },
ReverseServers: []*GoCQReverseWebsocketConfig{ ReverseServers: []*GoCQReverseWebSocketConfig{
{ {
Enabled: false, Enabled: false,
ReverseUrl: "ws://you_websocket_universal.server", ReverseURL: "ws://you_websocket_universal.server",
ReverseApiUrl: "ws://you_websocket_api.server", ReverseAPIURL: "ws://you_websocket_api.server",
ReverseEventUrl: "ws://you_websocket_event.server", ReverseEventURL: "ws://you_websocket_event.server",
ReverseReconnectInterval: 3000, ReverseReconnectInterval: 3000,
}, },
}, },
WebUi: &GoCqWebUi{ WebUI: &GoCQWebUI{
Enabled: true, Enabled: true,
Host: "127.0.0.1", Host: "127.0.0.1",
WebInput: false, WebInput: false,
WebUiPort: 9999, WebUIPort: 9999,
}, },
} }
} }
func Load(p string) *JsonConfig { //Load 加载配置文件
func Load(p string) *JSONConfig {
if !PathExists(p) { if !PathExists(p) {
log.Warnf("尝试加载配置文件 %v 失败: 文件不存在", p) log.Warnf("尝试加载配置文件 %v 失败: 文件不存在", p)
return nil return nil
} }
var dat map[string]interface{} var dat map[string]interface{}
var c = JsonConfig{} var c = JSONConfig{}
err := hjson.Unmarshal([]byte(ReadAllText(p)), &dat) err := hjson.Unmarshal([]byte(ReadAllText(p)), &dat)
if err == nil { if err == nil {
b, _ := json.Marshal(dat) b, _ := json.Marshal(dat)
@ -287,7 +296,8 @@ func Load(p string) *JsonConfig {
return &c return &c
} }
func (c *JsonConfig) Save(p string) error { //Save 写入配置文件至path
func (c *JSONConfig) Save(path string) error {
data, err := hjson.MarshalWithOptions(c, hjson.EncoderOptions{ data, err := hjson.MarshalWithOptions(c, hjson.EncoderOptions{
Eol: "\n", Eol: "\n",
BracesSameLine: true, BracesSameLine: true,
@ -296,5 +306,5 @@ func (c *JsonConfig) Save(p string) error {
if err != nil { if err != nil {
return err return err
} }
return WriteAllText(p, string(data)) return WriteAllText(path, string(data))
} }

View File

@ -10,8 +10,14 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
//MSG 消息Map
type MSG map[string]interface{} type MSG map[string]interface{}
//Get 尝试从消息Map中取出key为s的值,若不存在则返回MSG{}
//
//若所给key对应的值的类型是global.MSG,则返回此值
//
//若所给key对应值的类型不是global.MSG,则返回MSG{"__str__": Val}
func (m MSG) Get(s string) MSG { func (m MSG) Get(s string) MSG {
if v, ok := m[s]; ok { if v, ok := m[s]; ok {
if msg, ok := v.(MSG); ok { if msg, ok := v.(MSG); ok {
@ -22,6 +28,7 @@ func (m MSG) Get(s string) MSG {
return MSG{} return MSG{}
} }
//String 将消息Map转化为String。若Map存在key "__str__",则返回此key对应的值,否则将输出整张消息Map对应的JSON字符串
func (m MSG) String() string { func (m MSG) String() string {
if str, ok := m["__str__"]; ok { if str, ok := m["__str__"]; ok {
return fmt.Sprint(str) return fmt.Sprint(str)
@ -30,6 +37,7 @@ func (m MSG) String() string {
return str return str
} }
//Filter 定义了一个消息上报过滤接口
type Filter interface { type Filter interface {
Eval(payload MSG) bool Eval(payload MSG) bool
} }
@ -39,6 +47,7 @@ type operationNode struct {
filter Filter filter Filter
} }
//NotOperator 定义了过滤器中Not操作符
type NotOperator struct { type NotOperator struct {
operand Filter operand Filter
} }
@ -52,10 +61,12 @@ func notOperatorConstruct(argument gjson.Result) *NotOperator {
return op return op
} }
//Eval 对payload执行Not过滤
func (op *NotOperator) Eval(payload MSG) bool { func (op *NotOperator) Eval(payload MSG) bool {
return !op.operand.Eval(payload) return !op.operand.Eval(payload)
} }
//AndOperator 定义了过滤器中And操作符
type AndOperator struct { type AndOperator struct {
operands []operationNode operands []operationNode
} }
@ -91,6 +102,7 @@ func andOperatorConstruct(argument gjson.Result) *AndOperator {
return op return op
} }
//Eval 对payload执行And过滤
func (andOperator *AndOperator) Eval(payload MSG) bool { func (andOperator *AndOperator) Eval(payload MSG) bool {
res := true res := true
for _, operand := range andOperator.operands { for _, operand := range andOperator.operands {
@ -104,13 +116,14 @@ func (andOperator *AndOperator) Eval(payload MSG) bool {
res = res && operand.filter.Eval(val) res = res && operand.filter.Eval(val)
} }
if res == false { if !res {
break break
} }
} }
return res return res
} }
//OrOperator 定义了过滤器中Or操作符
type OrOperator struct { type OrOperator struct {
operands []Filter operands []Filter
} }
@ -127,17 +140,19 @@ func orOperatorConstruct(argument gjson.Result) *OrOperator {
return op return op
} }
//Eval 对payload执行Or过滤
func (op *OrOperator) Eval(payload MSG) bool { func (op *OrOperator) Eval(payload MSG) bool {
res := false res := false
for _, operand := range op.operands { for _, operand := range op.operands {
res = res || operand.Eval(payload) res = res || operand.Eval(payload)
if res == true { if res {
break break
} }
} }
return res return res
} }
//EqualOperator 定义了过滤器中Equal操作符
type EqualOperator struct { type EqualOperator struct {
operand string operand string
} }
@ -148,10 +163,12 @@ func equalOperatorConstruct(argument gjson.Result) *EqualOperator {
return op return op
} }
//Eval 对payload执行Equal过滤
func (op *EqualOperator) Eval(payload MSG) bool { func (op *EqualOperator) Eval(payload MSG) bool {
return payload.String() == op.operand return payload.String() == op.operand
} }
//NotEqualOperator 定义了过滤器中NotEqual操作符
type NotEqualOperator struct { type NotEqualOperator struct {
operand string operand string
} }
@ -162,10 +179,12 @@ func notEqualOperatorConstruct(argument gjson.Result) *NotEqualOperator {
return op return op
} }
//Eval 对payload执行NotEqual过滤
func (op *NotEqualOperator) Eval(payload MSG) bool { func (op *NotEqualOperator) Eval(payload MSG) bool {
return !(payload.String() == op.operand) return !(payload.String() == op.operand)
} }
//InOperator 定义了过滤器中In操作符
type InOperator struct { type InOperator struct {
operandString string operandString string
operandArray []string operandArray []string
@ -188,6 +207,7 @@ func inOperatorConstruct(argument gjson.Result) *InOperator {
return op return op
} }
//Eval 对payload执行In过滤
func (op *InOperator) Eval(payload MSG) bool { func (op *InOperator) Eval(payload MSG) bool {
payloadStr := payload.String() payloadStr := payload.String()
if op.operandArray != nil { if op.operandArray != nil {
@ -201,6 +221,7 @@ func (op *InOperator) Eval(payload MSG) bool {
return strings.Contains(op.operandString, payloadStr) return strings.Contains(op.operandString, payloadStr)
} }
//ContainsOperator 定义了过滤器中Contains操作符
type ContainsOperator struct { type ContainsOperator struct {
operand string operand string
} }
@ -214,10 +235,12 @@ func containsOperatorConstruct(argument gjson.Result) *ContainsOperator {
return op return op
} }
//Eval 对payload执行Contains过滤
func (op *ContainsOperator) Eval(payload MSG) bool { func (op *ContainsOperator) Eval(payload MSG) bool {
return strings.Contains(payload.String(), op.operand) return strings.Contains(payload.String(), op.operand)
} }
//RegexOperator 定义了过滤器中Regex操作符
type RegexOperator struct { type RegexOperator struct {
regex *regexp.Regexp regex *regexp.Regexp
} }
@ -231,11 +254,13 @@ func regexOperatorConstruct(argument gjson.Result) *RegexOperator {
return op return op
} }
//Eval 对payload执行RegexO过滤
func (op *RegexOperator) Eval(payload MSG) bool { func (op *RegexOperator) Eval(payload MSG) bool {
matched := op.regex.MatchString(payload.String()) matched := op.regex.MatchString(payload.String())
return matched return matched
} }
//Generate 根据给定操作符名opName及操作符参数argument创建一个过滤器实例
func Generate(opName string, argument gjson.Result) Filter { func Generate(opName string, argument gjson.Result) Filter {
switch opName { switch opName {
case "not": case "not":
@ -259,8 +284,10 @@ func Generate(opName string, argument gjson.Result) Filter {
} }
} }
//EventFilter 初始化一个nil过滤器
var EventFilter Filter = nil var EventFilter Filter = nil
//BootFilter 启动事件过滤器
func BootFilter() { func BootFilter() {
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {

View File

@ -9,7 +9,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/kardianos/osext"
"io" "io"
"io/ioutil" "io/ioutil"
"net" "net"
@ -21,75 +20,95 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/kardianos/osext"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
var ( const (
IMAGE_PATH = path.Join("data", "images") //ImagePath go-cqhttp使用的图片缓存目录
IMAGE_PATH_OLD = path.Join("data", "image") ImagePath = "data/images"
VOICE_PATH = path.Join("data", "voices") //ImagePathOld 兼容旧版go-cqhtto使用的图片缓存目录
VOICE_PATH_OLD = path.Join("data", "record") ImagePathOld = "data/image"
VIDEO_PATH = path.Join("data", "videos") //VoicePath go-cqhttp使用的语音缓存目录
CACHE_PATH = path.Join("data", "cache") VoicePath = "data/voices"
//VoicePathOld 兼容旧版go-cqhtto使用的语音缓存目录
HEADER_AMR = []byte("#!AMR") VoicePathOld = "data/record"
HEADER_SILK = []byte("\x02#!SILK_V3") //VideoPath go-cqhttp使用的视频缓存目录
VideoPath = "data/videos"
ErrSyntax = errors.New("syntax error") //CachePath go-cqhttp使用的缓存目录
CachePath = "data/cache"
) )
var (
//ErrSyntax Path语法错误时返回的错误
ErrSyntax = errors.New("syntax error")
//HeaderAmr AMR文件头
HeaderAmr = []byte("#!AMR")
//HeaderSilk Silkv3文件头
HeaderSilk = []byte("\x02#!SILK_V3")
)
//PathExists 判断给定path是否存在
func PathExists(path string) bool { func PathExists(path string) bool {
_, err := os.Stat(path) _, err := os.Stat(path)
return err == nil || os.IsExist(err) return err == nil || os.IsExist(err)
} }
//ReadAllText 读取给定path对应文件无法读取时返回空值
func ReadAllText(path string) string { func ReadAllText(path string) string {
b, err := ioutil.ReadFile(path) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
log.Error(err)
return "" return ""
} }
return string(b) return string(b)
} }
//WriteAllText 将给定text写入给定path
func WriteAllText(path, text string) error { func WriteAllText(path, text string) error {
return ioutil.WriteFile(path, []byte(text), 0644) return ioutil.WriteFile(path, []byte(text), 0644)
} }
//Check 检测err是否为nil
func Check(err error) { func Check(err error) {
if err != nil { if err != nil {
log.Fatalf("遇到错误: %v", err) log.Fatalf("遇到错误: %v", err)
} }
} }
//IsAMRorSILK 判断给定文件是否为Amr或Silk格式
func IsAMRorSILK(b []byte) bool { func IsAMRorSILK(b []byte) bool {
return bytes.HasPrefix(b, HEADER_AMR) || bytes.HasPrefix(b, HEADER_SILK) return bytes.HasPrefix(b, HeaderAmr) || bytes.HasPrefix(b, HeaderSilk)
} }
func FindFile(f, cache, PATH string) (data []byte, err error) { //FindFile 从给定的File寻找文件并返回文件byte数组。File是一个合法的URL。Path为文件寻找位置。
//对于HTTP/HTTPS形式的URLCache为"1"或空时表示启用缓存
func FindFile(file, cache, PATH string) (data []byte, err error) {
data, err = nil, ErrSyntax data, err = nil, ErrSyntax
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") { if strings.HasPrefix(file, "http") || strings.HasPrefix(file, "https") {
if cache == "" { if cache == "" {
cache = "1" cache = "1"
} }
hash := md5.Sum([]byte(f)) hash := md5.Sum([]byte(file))
cacheFile := path.Join(CACHE_PATH, hex.EncodeToString(hash[:])+".cache") cacheFile := path.Join(CachePath, hex.EncodeToString(hash[:])+".cache")
if PathExists(cacheFile) && cache == "1" { if PathExists(cacheFile) && cache == "1" {
return ioutil.ReadFile(cacheFile) return ioutil.ReadFile(cacheFile)
} }
data, err = GetBytes(f) data, err = GetBytes(file)
_ = ioutil.WriteFile(cacheFile, data, 0644) _ = ioutil.WriteFile(cacheFile, data, 0644)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else if strings.HasPrefix(f, "base64") { } else if strings.HasPrefix(file, "base64") {
data, err = base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", "")) data, err = base64.StdEncoding.DecodeString(strings.ReplaceAll(file, "base64://", ""))
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else if strings.HasPrefix(f, "file") { } else if strings.HasPrefix(file, "file") {
var fu *url.URL var fu *url.URL
fu, err = url.Parse(f) fu, err = url.Parse(file)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -100,8 +119,8 @@ func FindFile(f, cache, PATH string) (data []byte, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else if PathExists(path.Join(PATH, f)) { } else if PathExists(path.Join(PATH, file)) {
data, err = ioutil.ReadFile(path.Join(PATH, f)) data, err = ioutil.ReadFile(path.Join(PATH, file))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -109,19 +128,20 @@ func FindFile(f, cache, PATH string) (data []byte, err error) {
return return
} }
//DelFile 删除一个给定path并返回删除结果
func DelFile(path string) bool { func DelFile(path string) bool {
err := os.Remove(path) err := os.Remove(path)
if err != nil { if err != nil {
// 删除失败 // 删除失败
log.Error(err) log.Error(err)
return false return false
} else {
// 删除成功
log.Info(path + "删除成功")
return true
} }
// 删除成功
log.Info(path + "删除成功")
return true
} }
//ReadAddrFile 从给定path中读取合法的IP地址与端口,每个IP地址以换行符"\n"作为分隔
func ReadAddrFile(path string) []*net.TCPAddr { func ReadAddrFile(path string) []*net.TCPAddr {
d, err := ioutil.ReadFile(path) d, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
@ -140,10 +160,12 @@ func ReadAddrFile(path string) []*net.TCPAddr {
return ret return ret
} }
//WriteCounter 写入量计算实例
type WriteCounter struct { type WriteCounter struct {
Total uint64 Total uint64
} }
//Write 方法将写入的byte长度追加至写入的总长度Total中
func (wc *WriteCounter) Write(p []byte) (int, error) { func (wc *WriteCounter) Write(p []byte) (int, error) {
n := len(p) n := len(p)
wc.Total += uint64(n) wc.Total += uint64(n)
@ -151,12 +173,13 @@ func (wc *WriteCounter) Write(p []byte) (int, error) {
return n, nil return n, nil
} }
func (wc WriteCounter) PrintProgress() { //PrintProgress 方法将打印当前的总写入量
func (wc *WriteCounter) PrintProgress() {
fmt.Printf("\r%s", strings.Repeat(" ", 35)) fmt.Printf("\r%s", strings.Repeat(" ", 35))
fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total)) fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total))
} }
// UpdateFromStream copy form getlantern/go-update //UpdateFromStream copy form getlantern/go-update
func UpdateFromStream(updateWith io.Reader) (err error, errRecover error) { func UpdateFromStream(updateWith io.Reader) (err error, errRecover error) {
updatePath, err := osext.Executable() updatePath, err := osext.Executable()
if err != nil { if err != nil {

View File

@ -5,8 +5,6 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"github.com/guonaihong/gout"
"github.com/pkg/errors"
"io" "io"
"io/ioutil" "io/ioutil"
"net" "net"
@ -18,6 +16,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/guonaihong/gout"
"github.com/pkg/errors"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
@ -44,13 +45,18 @@ var (
MaxIdleConnsPerHost: 999, MaxIdleConnsPerHost: 999,
}, },
} }
//Proxy 存储Config.proxy_rewrite,用于设置代理
Proxy string Proxy string
//ErrOverSize 响应主体过大时返回此错误
ErrOverSize = errors.New("oversize") ErrOverSize = errors.New("oversize")
//UserAgent HTTP请求时使用的UA
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66" UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
) )
//GetBytes 对给定URL发送Get请求返回响应主体
func GetBytes(url string) ([]byte, error) { func GetBytes(url string) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
@ -76,6 +82,7 @@ func GetBytes(url string) ([]byte, error) {
return body, nil return body, nil
} }
//DownloadFile 将给定URL对应的文件下载至给定Path
func DownloadFile(url, path string, limit int64, headers map[string]string) error { func DownloadFile(url, path string, limit int64, headers map[string]string) error {
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0666) file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil { if err != nil {
@ -86,11 +93,11 @@ func DownloadFile(url, path string, limit int64, headers map[string]string) erro
if err != nil { if err != nil {
return err return err
} }
if headers != nil {
for k, v := range headers { for k, v := range headers {
req.Header.Set(k, v) req.Header.Set(k, v)
}
} }
if _, ok := headers["User-Agent"]; ok { if _, ok := headers["User-Agent"]; ok {
req.Header["User-Agent"] = []string{UserAgent} req.Header["User-Agent"] = []string{UserAgent}
} }
@ -109,6 +116,7 @@ func DownloadFile(url, path string, limit int64, headers map[string]string) erro
return nil return nil
} }
//DownloadFileMultiThreading 使用threadCount个线程将给定URL对应的文件下载至给定Path
func DownloadFileMultiThreading(url, path string, limit int64, threadCount int, headers map[string]string) error { func DownloadFileMultiThreading(url, path string, limit int64, threadCount int, headers map[string]string) error {
if threadCount < 2 { if threadCount < 2 {
return DownloadFile(url, path, limit, headers) return DownloadFile(url, path, limit, headers)
@ -138,10 +146,10 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
if err != nil { if err != nil {
return err return err
} }
if headers != nil {
for k, v := range headers { for k, v := range headers {
req.Header.Set(k, v) req.Header.Set(k, v)
}
} }
if _, ok := headers["User-Agent"]; ok { if _, ok := headers["User-Agent"]; ok {
req.Header["User-Agent"] = []string{UserAgent} req.Header["User-Agent"] = []string{UserAgent}
@ -168,9 +176,9 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
blockSize := func() int64 { blockSize := func() int64 {
if contentLength > 1024*1024 { if contentLength > 1024*1024 {
return (contentLength / int64(threadCount)) - 10 return (contentLength / int64(threadCount)) - 10
} else {
return contentLength
} }
return contentLength
}() }()
if blockSize == contentLength { if blockSize == contentLength {
return copyStream(resp.Body) return copyStream(resp.Body)
@ -189,7 +197,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
}) })
return nil return nil
} }
return errors.New("unknown status code.") return errors.New("unknown status code")
} }
// 下载分块 // 下载分块
downloadBlock := func(block *BlockMetaData) error { downloadBlock := func(block *BlockMetaData) error {
@ -202,11 +210,11 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
_, _ = file.Seek(block.BeginOffset, io.SeekStart) _, _ = file.Seek(block.BeginOffset, io.SeekStart)
writer := bufio.NewWriter(file) writer := bufio.NewWriter(file)
defer writer.Flush() defer writer.Flush()
if headers != nil {
for k, v := range headers { for k, v := range headers {
req.Header.Set(k, v) req.Header.Set(k, v)
}
} }
if _, ok := headers["User-Agent"]; ok { if _, ok := headers["User-Agent"]; ok {
req.Header["User-Agent"] = []string{UserAgent} req.Header["User-Agent"] = []string{UserAgent}
} }
@ -266,6 +274,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
return lastErr return lastErr
} }
//GetSliderTicket 通过给定的验证链接raw和id,获取验证结果Ticket
func GetSliderTicket(raw, id string) (string, error) { func GetSliderTicket(raw, id string) (string, error) {
var rsp string var rsp string
if err := gout.POST("https://api.shkong.com/gocqhttpapi/task").SetJSON(gout.H{ if err := gout.POST("https://api.shkong.com/gocqhttpapi/task").SetJSON(gout.H{
@ -281,6 +290,7 @@ func GetSliderTicket(raw, id string) (string, error) {
return g.Get("ticket").Str, nil return g.Get("ticket").Str, nil
} }
//QQMusicSongInfo 通过给定id在QQ音乐上查找曲目信息
func QQMusicSongInfo(id string) (gjson.Result, error) { func QQMusicSongInfo(id string) (gjson.Result, error) {
d, err := GetBytes(`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={%22comm%22:{%22ct%22:24,%22cv%22:0},%22songinfo%22:{%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22song_type%22:0,%22song_mid%22:%22%22,%22song_id%22:` + id + `},%22module%22:%22music.pf_song_detail_svr%22}}`) d, err := GetBytes(`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={%22comm%22:{%22ct%22:24,%22cv%22:0},%22songinfo%22:{%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22song_type%22:0,%22song_mid%22:%22%22,%22song_id%22:` + id + `},%22module%22:%22music.pf_song_detail_svr%22}}`)
if err != nil { if err != nil {
@ -289,6 +299,7 @@ func QQMusicSongInfo(id string) (gjson.Result, error) {
return gjson.ParseBytes(d).Get("songinfo.data"), nil return gjson.ParseBytes(d).Get("songinfo.data"), nil
} }
//NeteaseMusicSongInfo 通过给定id在wdd音乐上查找曲目信息
func NeteaseMusicSongInfo(id string) (gjson.Result, error) { func NeteaseMusicSongInfo(id string) (gjson.Result, error) {
d, err := GetBytes(fmt.Sprintf("http://music.163.com/api/song/detail/?id=%s&ids=%%5B%s%%5D", id, id)) d, err := GetBytes(fmt.Sprintf("http://music.163.com/api/song/detail/?id=%s&ids=%%5B%s%%5D", id, id))
if err != nil { if err != nil {

View File

@ -21,6 +21,15 @@ var falseSet = map[string]struct{}{
"0": {}, "0": {},
} }
//EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal
//
//支持的合法类型有
//
//type bool
//
//type gjson.True or gjson.False
//
//type string "true","yes","1" or "false","no","0" (case insensitive)
func EnsureBool(p interface{}, defaultVal bool) bool { func EnsureBool(p interface{}, defaultVal bool) bool {
var str string var str string
if b, ok := p.(bool); ok { if b, ok := p.(bool); ok {
@ -54,9 +63,13 @@ func EnsureBool(p interface{}, defaultVal bool) bool {
} }
// VersionNameCompare 检查版本名是否需要更新, 仅适用于 go-cqhttp 的版本命名规则 // VersionNameCompare 检查版本名是否需要更新, 仅适用于 go-cqhttp 的版本命名规则
//
// 例: v0.9.29-fix2 == v0.9.29-fix2 -> false // 例: v0.9.29-fix2 == v0.9.29-fix2 -> false
//
// v0.9.29-fix1 < v0.9.29-fix2 -> true // v0.9.29-fix1 < v0.9.29-fix2 -> true
//
// v0.9.29-fix2 > v0.9.29-fix1 -> false // v0.9.29-fix2 > v0.9.29-fix1 -> false
//
// v0.9.29-fix2 < v0.9.30 -> true // v0.9.29-fix2 < v0.9.30 -> true
func VersionNameCompare(current, remote string) bool { func VersionNameCompare(current, remote string) bool {
sp := regexp.MustCompile(`[0-9]\d*`) sp := regexp.MustCompile(`[0-9]\d*`)
@ -72,8 +85,9 @@ func VersionNameCompare(current, remote string) bool {
return len(cur) < len(re) return len(cur) < len(re)
} }
func SplitUrl(s string) []string { //SplitURL 将给定URL字符串分割为两部分用于URL预处理防止风控
reg := regexp.MustCompile(`[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?`) func SplitURL(s string) []string {
reg := regexp.MustCompile(`(?i)[a-z\d][-a-z\d]{0,62}(\.[a-z\d][-a-z\d]{0,62})+\.?`)
idx := reg.FindAllStringIndex(s, -1) idx := reg.FindAllStringIndex(s, -1)
if len(idx) == 0 { if len(idx) == 0 {
return []string{s} return []string{s}

View File

@ -9,13 +9,15 @@ import (
var limiter *rate.Limiter var limiter *rate.Limiter
var limitEnable = false var limitEnable = false
//RateLimit 执行API调用速率限制
func RateLimit(ctx context.Context) { func RateLimit(ctx context.Context) {
if limitEnable { if limitEnable {
_ = limiter.Wait(ctx) _ = limiter.Wait(ctx)
} }
} }
func InitLimiter(r float64, b int) { //InitLimiter 初始化速率限制器
func InitLimiter(frequency float64, bucketSize int) {
limitEnable = true limitEnable = true
limiter = rate.NewLimiter(rate.Limit(r), b) limiter = rate.NewLimiter(rate.Limit(frequency), bucketSize)
} }

25
go.mod
View File

@ -7,20 +7,41 @@ require (
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0
github.com/gin-contrib/pprof v1.3.0 github.com/gin-contrib/pprof v1.3.0
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/google/uuid v1.1.5 // indirect
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.4 github.com/guonaihong/gout v0.1.4
github.com/hjson/hjson-go v3.1.0+incompatible github.com/hjson/hjson-go v3.1.0+incompatible
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.10 github.com/json-iterator/go v1.1.10
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/strftime v1.0.3 // indirect github.com/lestrrat-go/strftime v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nxadm/tail v1.4.6 // indirect
github.com/onsi/ginkgo v1.14.2 // indirect
github.com/onsi/gomega v1.10.4 // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.7.0 github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.7.0 // indirect
github.com/syndtr/goleveldb v1.0.0 github.com/syndtr/goleveldb v1.0.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tidwall/gjson v1.6.7 github.com/tidwall/gjson v1.6.7
github.com/ugorji/go v1.2.3 // indirect
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
golang.org/x/text v0.3.5 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
) )

98
go.sum
View File

@ -1,18 +1,21 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20210110160231-b83dd4cf38a5 h1:ee6LafOcoVM0nox2UxiIJgomgRP4pDJe5aeT/rq2o/U=
github.com/Mrs4s/MiraiGo v0.0.0-20210110160231-b83dd4cf38a5/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
github.com/Mrs4s/MiraiGo v0.0.0-20210115215446-8ee19f60514b h1:am1XzFc9Q5wSLLkrhjyDf5/IWq3qgNwJl2zzIRp2haw= github.com/Mrs4s/MiraiGo v0.0.0-20210115215446-8ee19f60514b h1:am1XzFc9Q5wSLLkrhjyDf5/IWq3qgNwJl2zzIRp2haw=
github.com/Mrs4s/MiraiGo v0.0.0-20210115215446-8ee19f60514b/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo= github.com/Mrs4s/MiraiGo v0.0.0-20210115215446-8ee19f60514b/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0= github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0=
github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0= github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
@ -21,6 +24,7 @@ github.com/gin-gonic/gin v1.6.0/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwv
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
@ -28,6 +32,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -39,51 +45,91 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.5 h1:kxhtnfFVi+rYdOALN0B3k9UT86zVJKfBimRaciULW4I=
github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g= github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g=
github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic= github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic=
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw= github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio= github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4= github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/strftime v1.0.3 h1:qqOPU7y+TM8Y803I8fG9c/DyKG3xH/xkng6keC1015Q= github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
github.com/lestrrat-go/strftime v1.0.3/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g= github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.6 h1:11TGpSHY7Esh/i/qnq02Jo5oVrI1Gue8Slbq0ujPZFQ=
github.com/nxadm/tail v1.4.6/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M=
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.4 h1:NiTx7EEvBzu9sFOD1zORteLSt3o8gnlvZZwSE9TnY9U=
github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
@ -95,7 +141,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
@ -110,11 +160,16 @@ github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.3 h1:WbFSXLxDFKVN69Sk8t+XHGzVCD7R8UoAATR8NqZgTbk=
github.com/ugorji/go v1.2.3/go.mod h1:5l8GZ8hZvmL4uMdy+mhCO1LjswGRYco9Q3HfuisB21A=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.3 h1:/mVYEV+Jo3IZKeA5gBngN0AvNnQltEDkR+eQikkWQu0=
github.com/ugorji/go/codec v1.2.3/go.mod h1:5FxzDJIgeiWJZslYHPj+LS1dq1ZBQVelZFnjsFGI/Uc=
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk= github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I= github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@ -129,6 +184,10 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -136,14 +195,31 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 h1:nVuTkr9L6Bq62qpUqKo/RnZCFfzDBL0bYo6w9OJUqZY=
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@ -152,6 +228,7 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
@ -171,12 +248,25 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

82
main.go
View File

@ -16,12 +16,13 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/Mrs4s/go-cqhttp/server" "github.com/Mrs4s/go-cqhttp/server"
"github.com/guonaihong/gout" "github.com/guonaihong/gout"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/term"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/client"
@ -45,23 +46,23 @@ func init() {
if err == nil { if err == nil {
log.SetOutput(io.MultiWriter(os.Stderr, w)) log.SetOutput(io.MultiWriter(os.Stderr, w))
} }
if !global.PathExists(global.IMAGE_PATH) { if !global.PathExists(global.ImagePath) {
if err := os.MkdirAll(global.IMAGE_PATH, 0755); err != nil { if err := os.MkdirAll(global.ImagePath, 0755); err != nil {
log.Fatalf("创建图片缓存文件夹失败: %v", err) log.Fatalf("创建图片缓存文件夹失败: %v", err)
} }
} }
if !global.PathExists(global.VOICE_PATH) { if !global.PathExists(global.VoicePath) {
if err := os.MkdirAll(global.VOICE_PATH, 0755); err != nil { if err := os.MkdirAll(global.VoicePath, 0755); err != nil {
log.Fatalf("创建语音缓存文件夹失败: %v", err) log.Fatalf("创建语音缓存文件夹失败: %v", err)
} }
} }
if !global.PathExists(global.VIDEO_PATH) { if !global.PathExists(global.VideoPath) {
if err := os.MkdirAll(global.VIDEO_PATH, 0755); err != nil { if err := os.MkdirAll(global.VideoPath, 0755); err != nil {
log.Fatalf("创建视频缓存文件夹失败: %v", err) log.Fatalf("创建视频缓存文件夹失败: %v", err)
} }
} }
if !global.PathExists(global.CACHE_PATH) { if !global.PathExists(global.CachePath) {
if err := os.MkdirAll(global.CACHE_PATH, 0755); err != nil { if err := os.MkdirAll(global.CachePath, 0755); err != nil {
log.Fatalf("创建发送图片缓存文件夹失败: %v", err) log.Fatalf("创建发送图片缓存文件夹失败: %v", err)
} }
} }
@ -69,24 +70,24 @@ func init() {
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.") log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.hjson 文件.") log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.hjson 文件.")
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
conf := global.CQHttpApiConfig{} conf := global.CQHTTPAPIConfig{}
if err := json.Unmarshal([]byte(global.ReadAllText("cqhttp.json")), &conf); err != nil { if err := json.Unmarshal([]byte(global.ReadAllText("cqhttp.json")), &conf); err != nil {
log.Fatalf("读取文件 cqhttp.json 失败: %v", err) log.Fatalf("读取文件 cqhttp.json 失败: %v", err)
} }
goConf := global.DefaultConfig() goConf := global.DefaultConfig()
goConf.AccessToken = conf.AccessToken goConf.AccessToken = conf.AccessToken
goConf.HttpConfig.Host = conf.Host goConf.HTTPConfig.Host = conf.Host
goConf.HttpConfig.Port = conf.Port goConf.HTTPConfig.Port = conf.Port
goConf.WSConfig.Host = conf.WSHost goConf.WSConfig.Host = conf.WSHost
goConf.WSConfig.Port = conf.WSPort goConf.WSConfig.Port = conf.WSPort
if conf.PostUrl != "" { if conf.PostURL != "" {
goConf.HttpConfig.PostUrls[conf.PostUrl] = conf.Secret goConf.HTTPConfig.PostUrls[conf.PostURL] = conf.Secret
} }
if conf.UseWsReverse { if conf.UseWsReverse {
goConf.ReverseServers[0].Enabled = true goConf.ReverseServers[0].Enabled = true
goConf.ReverseServers[0].ReverseUrl = conf.WSReverseUrl goConf.ReverseServers[0].ReverseURL = conf.WSReverseURL
goConf.ReverseServers[0].ReverseApiUrl = conf.WSReverseApiUrl goConf.ReverseServers[0].ReverseAPIURL = conf.WSReverseAPIURL
goConf.ReverseServers[0].ReverseEventUrl = conf.WSReverseEventUrl goConf.ReverseServers[0].ReverseEventURL = conf.WSReverseEventURL
goConf.ReverseServers[0].ReverseReconnectInterval = conf.WSReverseReconnectInterval goConf.ReverseServers[0].ReverseReconnectInterval = conf.WSReverseReconnectInterval
} }
if err := goConf.Save("config.hjson"); err != nil { if err := goConf.Save("config.hjson"); err != nil {
@ -97,6 +98,7 @@ func init() {
} }
func main() { func main() {
var byteKey []byte var byteKey []byte
var isFastStart = false var isFastStart = false
arg := os.Args arg := os.Args
@ -120,7 +122,7 @@ func main() {
} }
} }
var conf *global.JsonConfig var conf *global.JSONConfig
if global.PathExists("config.json") { if global.PathExists("config.json") {
conf = global.Load("config.json") conf = global.Load("config.json")
_ = conf.Save("config.hjson") _ = conf.Save("config.hjson")
@ -130,16 +132,16 @@ func main() {
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64) uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
pwd := os.Getenv("PASS") pwd := os.Getenv("PASS")
post := os.Getenv("HTTP_POST") post := os.Getenv("HTTP_POST")
conf = &global.JsonConfig{ conf = &global.JSONConfig{
Uin: uin, Uin: uin,
Password: pwd, Password: pwd,
HttpConfig: &global.GoCQHttpConfig{ HTTPConfig: &global.GoCQHTTPConfig{
Enabled: true, Enabled: true,
Host: "0.0.0.0", Host: "0.0.0.0",
Port: 5700, Port: 5700,
PostUrls: map[string]string{}, PostUrls: map[string]string{},
}, },
WSConfig: &global.GoCQWebsocketConfig{ WSConfig: &global.GoCQWebSocketConfig{
Enabled: true, Enabled: true,
Host: "0.0.0.0", Host: "0.0.0.0",
Port: 6700, Port: 6700,
@ -148,7 +150,7 @@ func main() {
Debug: os.Getenv("DEBUG") == "true", Debug: os.Getenv("DEBUG") == "true",
} }
if post != "" { if post != "" {
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET") conf.HTTPConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
} }
} else { } else {
conf = global.Load("config.hjson") conf = global.Load("config.hjson")
@ -213,7 +215,7 @@ func main() {
log.Warnf("已开启Debug模式.") log.Warnf("已开启Debug模式.")
log.Debugf("开发交流群: 192548878") log.Debugf("开发交流群: 192548878")
server.Debug = true server.Debug = true
if conf.WebUi == nil || !conf.WebUi.Enabled { if conf.WebUI == nil || !conf.WebUI.Enabled {
log.Warnf("警告: 在Debug模式下未启用WebUi服务, 将无法进行性能分析.") log.Warnf("警告: 在Debug模式下未启用WebUi服务, 将无法进行性能分析.")
} }
} }
@ -231,7 +233,7 @@ func main() {
} }
if conf.EncryptPassword && conf.PasswordEncrypted == "" { if conf.EncryptPassword && conf.PasswordEncrypted == "" {
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)") log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
byteKey, _ := terminal.ReadPassword(int(os.Stdin.Fd())) byteKey, _ := term.ReadPassword(int(os.Stdin.Fd()))
key := md5.Sum(byteKey) key := md5.Sum(byteKey)
if encrypted := EncryptPwd(conf.Password, key[:]); encrypted != "" { if encrypted := EncryptPwd(conf.Password, key[:]); encrypted != "" {
conf.Password = "" conf.Password = ""
@ -255,7 +257,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
}() }()
byteKey, _ = terminal.ReadPassword(int(os.Stdin.Fd())) byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
cancel <- struct{}{} cancel <- struct{}{}
} else { } else {
log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.") log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.")
@ -308,26 +310,26 @@ func main() {
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ") log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
return true return true
}) })
if conf.WebUi == nil { if conf.WebUI == nil {
conf.WebUi = &global.GoCqWebUi{ conf.WebUI = &global.GoCQWebUI{
Enabled: true, Enabled: true,
WebInput: false, WebInput: false,
Host: "0.0.0.0", Host: "0.0.0.0",
WebUiPort: 9999, WebUIPort: 9999,
} }
} }
if conf.WebUi.WebUiPort <= 0 { if conf.WebUI.WebUIPort <= 0 {
conf.WebUi.WebUiPort = 9999 conf.WebUI.WebUIPort = 9999
} }
if conf.WebUi.Host == "" { if conf.WebUI.Host == "" {
conf.WebUi.Host = "127.0.0.1" conf.WebUI.Host = "127.0.0.1"
} }
global.Proxy = conf.ProxyRewrite global.Proxy = conf.ProxyRewrite
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli) b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUI.Host, conf.WebUI.WebUIPort), cli)
c := server.Console c := server.Console
r := server.Restart r := server.Restart
go checkUpdate() go checkUpdate()
signal.Notify(c, os.Interrupt, os.Kill) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
select { select {
case <-c: case <-c:
b.Release() b.Release()
@ -338,6 +340,7 @@ func main() {
} }
} }
//EncryptPwd 通过给定key加密给定pwd
func EncryptPwd(pwd string, key []byte) string { func EncryptPwd(pwd string, key []byte) string {
tea := binary.NewTeaCipher(key) tea := binary.NewTeaCipher(key)
if tea == nil { if tea == nil {
@ -346,6 +349,7 @@ func EncryptPwd(pwd string, key []byte) string {
return base64.StdEncoding.EncodeToString(tea.Encrypt([]byte(pwd))) return base64.StdEncoding.EncodeToString(tea.Encrypt([]byte(pwd)))
} }
//DecryptPwd 通过给定key解密给定ePwd
func DecryptPwd(ePwd string, key []byte) string { func DecryptPwd(ePwd string, key []byte) string {
defer func() { defer func() {
if pan := recover(); pan != nil { if pan := recover(); pan != nil {
@ -387,7 +391,7 @@ func checkUpdate() {
log.Infof("检查更新完成. 当前已运行最新版本.") log.Infof("检查更新完成. 当前已运行最新版本.")
} }
func selfUpdate(imageUrl string) { func selfUpdate(imageURL string) {
console := bufio.NewReader(os.Stdin) console := bufio.NewReader(os.Stdin)
readLine := func() (str string) { readLine := func() (str string) {
str, _ = console.ReadString('\n') str, _ = console.ReadString('\n')
@ -415,8 +419,8 @@ func selfUpdate(imageUrl string) {
url := fmt.Sprintf( url := fmt.Sprintf(
"%v/Mrs4s/go-cqhttp/releases/download/%v/go-cqhttp-%v-%v-%v", "%v/Mrs4s/go-cqhttp/releases/download/%v/go-cqhttp-%v-%v-%v",
func() string { func() string {
if imageUrl != "" { if imageURL != "" {
return imageUrl return imageURL
} }
return "https://github.com" return "https://github.com"
}(), }(),
@ -458,7 +462,7 @@ func selfUpdate(imageUrl string) {
} }
func restart(Args []string) { func restart(Args []string) {
cmd := &exec.Cmd{} var cmd *exec.Cmd
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
file, err := exec.LookPath(Args[0]) file, err := exec.LookPath(Args[0])
if err != nil { if err != nil {
@ -485,5 +489,5 @@ func restart(Args []string) {
Stdout: os.Stdout, Stdout: os.Stdout,
} }
} }
cmd.Start() _ = cmd.Start()
} }

View File

@ -5,8 +5,6 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/gin-contrib/pprof"
"image" "image"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -14,8 +12,12 @@ import (
"os/signal" "os/signal"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/gin-contrib/pprof"
"github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global" "github.com/Mrs4s/go-cqhttp/global"
@ -34,13 +36,13 @@ var Console = make(chan os.Signal, 1)
var Restart = make(chan struct{}, 1) var Restart = make(chan struct{}, 1)
var JsonConfig *global.JsonConfig var JSONConfig *global.JSONConfig
type webServer struct { type webServer struct {
engine *gin.Engine engine *gin.Engine
bot *coolq.CQBot bot *coolq.CQBot
Cli *client.QQClient Cli *client.QQClient
Conf *global.JsonConfig //old config Conf *global.JSONConfig //old config
Console *bufio.Reader Console *bufio.Reader
} }
@ -68,7 +70,7 @@ func Failed(code int, msg string) coolq.MSG {
func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot { func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
s.Cli = cli s.Cli = cli
s.Conf = GetConf() s.Conf = GetConf()
JsonConfig = s.Conf JSONConfig = s.Conf
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
s.engine = gin.New() s.engine = gin.New()
@ -79,7 +81,7 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
go func() { go func() {
//开启端口监听 //开启端口监听
if s.Conf.WebUi != nil && s.Conf.WebUi.Enabled { if s.Conf.WebUI != nil && s.Conf.WebUI.Enabled {
if Debug { if Debug {
pprof.Register(s.engine) pprof.Register(s.engine)
log.Debugf("pprof 性能分析服务已启动在 http://%v/debug/pprof, 如果有任何性能问题请下载报告并提交给开发者", addr) log.Debugf("pprof 性能分析服务已启动在 http://%v/debug/pprof, 如果有任何性能问题请下载报告并提交给开发者", addr)
@ -91,14 +93,14 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
log.Error(err) log.Error(err)
log.Infof("请检查端口是否被占用.") log.Infof("请检查端口是否被占用.")
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c <-c
os.Exit(1) os.Exit(1)
} }
} else { } else {
//关闭端口监听 //关闭端口监听
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c <-c
os.Exit(1) os.Exit(1)
} }
@ -155,13 +157,17 @@ func (s *webServer) Dologin() {
os.Exit(0) os.Exit(0)
} }
rsp, err = cli.SubmitTicket(ticket) rsp, err = cli.SubmitTicket(ticket)
if err != nil {
log.Warnf("错误: " + err.Error())
os.Exit(0)
}
continue continue
case client.NeedCaptcha: case client.NeedCaptcha:
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644) _ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage)) img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
fmt.Println(asciiart.New("image", img).Art) fmt.Println(asciiart.New("image", img).Art)
if conf.WebUi != nil && conf.WebUi.WebInput { if conf.WebUI != nil && conf.WebUI.WebInput {
log.Warnf("请输入验证码 (captcha.jpg) (http://%s:%d/admin/do_web_write 输入)", conf.WebUi.Host, conf.WebUi.WebUiPort) log.Warnf("请输入验证码 (captcha.jpg) (http://%s:%d/admin/do_web_write 输入)", conf.WebUI.Host, conf.WebUI.WebUIPort)
text = <-WebInput text = <-WebInput
} else { } else {
log.Warn("请输入验证码 (captcha.jpg) (Enter 提交)") log.Warn("请输入验证码 (captcha.jpg) (Enter 提交)")
@ -206,8 +212,8 @@ func (s *webServer) Dologin() {
return return
case client.UnsafeDeviceError: case client.UnsafeDeviceError:
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl) log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
if conf.WebUi != nil && conf.WebUi.WebInput { if conf.WebUI != nil && conf.WebUI.WebInput {
log.Infof(" (http://%s:%d/admin/do_web_write 确认后继续)....", conf.WebUi.Host, conf.WebUi.WebUiPort) log.Infof(" (http://%s:%d/admin/do_web_write 确认后继续)....", conf.WebUI.Host, conf.WebUI.WebUIPort)
text = <-WebInput text = <-WebInput
} else { } else {
log.Infof("按 Enter 继续....") log.Infof("按 Enter 继续....")
@ -260,7 +266,7 @@ func (s *webServer) Dologin() {
global.BootFilter() global.BootFilter()
global.InitCodec() global.InitCodec()
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
coolq.SplitUrl = conf.FixUrl coolq.SplitUrl = conf.FixURL
coolq.ForceFragmented = conf.ForceFragmented coolq.ForceFragmented = conf.ForceFragmented
log.Info("资源初始化完成, 开始处理信息.") log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!") log.Info("アトリは、高性能ですから!")
@ -323,9 +329,9 @@ func (s *webServer) admin(c *gin.Context) {
} }
// 获取当前配置文件信息 // 获取当前配置文件信息
func GetConf() *global.JsonConfig { func GetConf() *global.JSONConfig {
if JsonConfig != nil { if JSONConfig != nil {
return JsonConfig return JSONConfig
} }
conf := global.Load("config.hjson") conf := global.Load("config.hjson")
return conf return conf
@ -385,7 +391,7 @@ func AuthMiddleWare() gin.HandlerFunc {
} }
func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
JsonConfig = nil JSONConfig = nil
conf := GetConf() conf := GetConf()
OldConf := s.Conf OldConf := s.Conf
cli := client.NewClient(conf.Uin, conf.Password) cli := client.NewClient(conf.Uin, conf.Password)
@ -424,7 +430,7 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
s.Cli = cli s.Cli = cli
s.Dologin() s.Dologin()
//关闭之前的 server //关闭之前的 server
if OldConf.HttpConfig != nil && OldConf.HttpConfig.Enabled { if OldConf.HTTPConfig != nil && OldConf.HTTPConfig.Enabled {
HttpServer.ShutDown() HttpServer.ShutDown()
} }
//if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled { //if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled {
@ -437,31 +443,31 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
func (s *webServer) UpServer() { func (s *webServer) UpServer() {
conf := GetConf() conf := GetConf()
if conf.HttpConfig != nil && conf.HttpConfig.Enabled { if conf.HTTPConfig != nil && conf.HTTPConfig.Enabled {
go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, s.bot) go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HTTPConfig.Host, conf.HTTPConfig.Port), conf.AccessToken, s.bot)
for k, v := range conf.HttpConfig.PostUrls { for k, v := range conf.HTTPConfig.PostUrls {
NewHttpClient().Run(k, v, conf.HttpConfig.Timeout, s.bot) NewHttpClient().Run(k, v, conf.HTTPConfig.Timeout, s.bot)
} }
} }
if conf.WSConfig != nil && conf.WSConfig.Enabled { if conf.WSConfig != nil && conf.WSConfig.Enabled {
go WebsocketServer.Run(fmt.Sprintf("%s:%d", conf.WSConfig.Host, conf.WSConfig.Port), conf.AccessToken, s.bot) go WebSocketServer.Run(fmt.Sprintf("%s:%d", conf.WSConfig.Host, conf.WSConfig.Port), conf.AccessToken, s.bot)
} }
for _, rc := range conf.ReverseServers { for _, rc := range conf.ReverseServers {
go NewWebsocketClient(rc, conf.AccessToken, s.bot).Run() go NewWebSocketClient(rc, conf.AccessToken, s.bot).Run()
} }
} }
// 暂不支持ws服务的重启 // 暂不支持ws服务的重启
func (s *webServer) ReloadServer() { func (s *webServer) ReloadServer() {
conf := GetConf() conf := GetConf()
if conf.HttpConfig != nil && conf.HttpConfig.Enabled { if conf.HTTPConfig != nil && conf.HTTPConfig.Enabled {
go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, s.bot) go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HTTPConfig.Host, conf.HTTPConfig.Port), conf.AccessToken, s.bot)
for k, v := range conf.HttpConfig.PostUrls { for k, v := range conf.HTTPConfig.PostUrls {
NewHttpClient().Run(k, v, conf.HttpConfig.Timeout, s.bot) NewHttpClient().Run(k, v, conf.HTTPConfig.Timeout, s.bot)
} }
} }
for _, rc := range conf.ReverseServers { for _, rc := range conf.ReverseServers {
go NewWebsocketClient(rc, conf.AccessToken, s.bot).Run() go NewWebSocketClient(rc, conf.AccessToken, s.bot).Run()
} }
} }
@ -472,7 +478,6 @@ func AdminDoRestart(s *webServer, c *gin.Context) {
s.Cli = nil s.Cli = nil
s.DoReLogin() s.DoReLogin()
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
return
} }
// 进程重启 // 进程重启
@ -485,7 +490,6 @@ func AdminProcessRestart(s *webServer, c *gin.Context) {
func AdminDoRestartDocker(s *webServer, c *gin.Context) { func AdminDoRestartDocker(s *webServer, c *gin.Context) {
Console <- os.Kill Console <- os.Kill
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
return
} }
// web输入 html 页面 // web输入 html 页面
@ -527,7 +531,7 @@ func AdminDoConfigBase(s *webServer, c *gin.Context) {
log.Fatalf("保存 config.hjson 时出现错误: %v", err) log.Fatalf("保存 config.hjson 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err))) c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
} else { } else {
JsonConfig = nil JSONConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
} }
} }
@ -536,23 +540,23 @@ func AdminDoConfigBase(s *webServer, c *gin.Context) {
func AdminDoConfigHttp(s *webServer, c *gin.Context) { func AdminDoConfigHttp(s *webServer, c *gin.Context) {
conf := GetConf() conf := GetConf()
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16) p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
conf.HttpConfig.Port = uint16(p) conf.HTTPConfig.Port = uint16(p)
conf.HttpConfig.Host = c.PostForm("host") conf.HTTPConfig.Host = c.PostForm("host")
if c.PostForm("enable") == "true" { if c.PostForm("enable") == "true" {
conf.HttpConfig.Enabled = true conf.HTTPConfig.Enabled = true
} else { } else {
conf.HttpConfig.Enabled = false conf.HTTPConfig.Enabled = false
} }
t, _ := strconv.ParseInt(c.PostForm("timeout"), 10, 32) t, _ := strconv.ParseInt(c.PostForm("timeout"), 10, 32)
conf.HttpConfig.Timeout = int32(t) conf.HTTPConfig.Timeout = int32(t)
if c.PostForm("post_url") != "" { if c.PostForm("post_url") != "" {
conf.HttpConfig.PostUrls[c.PostForm("post_url")] = c.PostForm("post_secret") conf.HTTPConfig.PostUrls[c.PostForm("post_url")] = c.PostForm("post_secret")
} }
if err := conf.Save("config.hjson"); err != nil { if err := conf.Save("config.hjson"); err != nil {
log.Fatalf("保存 config.hjson 时出现错误: %v", err) log.Fatalf("保存 config.hjson 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err))) c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
} else { } else {
JsonConfig = nil JSONConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
} }
} }
@ -572,7 +576,7 @@ func AdminDoConfigWs(s *webServer, c *gin.Context) {
log.Fatalf("保存 config.hjson 时出现错误: %v", err) log.Fatalf("保存 config.hjson 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err))) c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
} else { } else {
JsonConfig = nil JSONConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
} }
} }
@ -580,9 +584,9 @@ func AdminDoConfigWs(s *webServer, c *gin.Context) {
// 反向ws配置修改 // 反向ws配置修改
func AdminDoConfigReverse(s *webServer, c *gin.Context) { func AdminDoConfigReverse(s *webServer, c *gin.Context) {
conf := GetConf() conf := GetConf()
conf.ReverseServers[0].ReverseApiUrl = c.PostForm("reverse_api_url") conf.ReverseServers[0].ReverseAPIURL = c.PostForm("reverse_api_url")
conf.ReverseServers[0].ReverseUrl = c.PostForm("reverse_url") conf.ReverseServers[0].ReverseURL = c.PostForm("reverse_url")
conf.ReverseServers[0].ReverseEventUrl = c.PostForm("reverse_event_url") conf.ReverseServers[0].ReverseEventURL = c.PostForm("reverse_event_url")
t, _ := strconv.ParseUint(c.PostForm("reverse_reconnect_interval"), 10, 16) t, _ := strconv.ParseUint(c.PostForm("reverse_reconnect_interval"), 10, 16)
conf.ReverseServers[0].ReverseReconnectInterval = uint16(t) conf.ReverseServers[0].ReverseReconnectInterval = uint16(t)
if c.PostForm("enable") == "true" { if c.PostForm("enable") == "true" {
@ -594,7 +598,7 @@ func AdminDoConfigReverse(s *webServer, c *gin.Context) {
log.Fatalf("保存 config.hjson 时出现错误: %v", err) log.Fatalf("保存 config.hjson 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err))) c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
} else { } else {
JsonConfig = nil JSONConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
} }
} }
@ -613,7 +617,7 @@ func AdminDoConfigJson(s *webServer, c *gin.Context) {
log.Fatalf("保存 config.hjson 时出现错误: %v", err) log.Fatalf("保存 config.hjson 时出现错误: %v", err)
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err))) c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
} else { } else {
JsonConfig = nil JSONConfig = nil
c.JSON(200, coolq.OK(coolq.MSG{})) c.JSON(200, coolq.OK(coolq.MSG{}))
} }
} }

View File

@ -123,7 +123,11 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
} }
if c.secret != "" { if c.secret != "" {
mac := hmac.New(sha1.New, []byte(c.secret)) mac := hmac.New(sha1.New, []byte(c.secret))
mac.Write([]byte(m.ToJson())) _, err := mac.Write([]byte(m.ToJson()))
if err != nil {
log.Error(err)
return nil
}
h["X-Signature"] = "sha1=" + hex.EncodeToString(mac.Sum(nil)) h["X-Signature"] = "sha1=" + hex.EncodeToString(mac.Sum(nil))
} }
return h return h
@ -576,9 +580,7 @@ func (s *httpServer) ShutDown() {
if err := s.Http.Shutdown(ctx); err != nil { if err := s.Http.Shutdown(ctx); err != nil {
log.Fatal("http Server Shutdown:", err) log.Fatal("http Server Shutdown:", err)
} }
select { <-ctx.Done()
case <-ctx.Done(): log.Println("timeout of 5 seconds.")
log.Println("timeout of 5 seconds.")
}
log.Println("http Server exiting") log.Println("http Server exiting")
} }

View File

@ -17,36 +17,38 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
type websocketServer struct { type webSocketServer struct {
bot *coolq.CQBot bot *coolq.CQBot
token string token string
eventConn []*websocketConn eventConn []*webSocketConn
eventConnMutex sync.Mutex eventConnMutex sync.Mutex
handshake string handshake string
} }
type websocketClient struct { //WebSocketClient Websocket客户端实例
conf *global.GoCQReverseWebsocketConfig type WebSocketClient struct {
conf *global.GoCQReverseWebSocketConfig
token string token string
bot *coolq.CQBot bot *coolq.CQBot
universalConn *websocketConn universalConn *webSocketConn
eventConn *websocketConn eventConn *webSocketConn
} }
type websocketConn struct { type webSocketConn struct {
*websocket.Conn *websocket.Conn
sync.Mutex sync.Mutex
} }
var WebsocketServer = &websocketServer{} //WebSocketServer 初始化一个WebSocketServer实例
var WebSocketServer = &webSocketServer{}
var upgrader = websocket.Upgrader{ var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { CheckOrigin: func(r *http.Request) bool {
return true return true
}, },
} }
func (s *websocketServer) Run(addr, authToken string, b *coolq.CQBot) { func (s *webSocketServer) Run(addr, authToken string, b *coolq.CQBot) {
s.token = authToken s.token = authToken
s.bot = b s.bot = b
s.handshake = fmt.Sprintf(`{"_post_method":2,"meta_event_type":"lifecycle","post_type":"meta_event","self_id":%d,"sub_type":"connect","time":%d}`, s.handshake = fmt.Sprintf(`{"_post_method":2,"meta_event_type":"lifecycle","post_type":"meta_event","self_id":%d,"sub_type":"connect","time":%d}`,
@ -61,29 +63,31 @@ func (s *websocketServer) Run(addr, authToken string, b *coolq.CQBot) {
}() }()
} }
func NewWebsocketClient(conf *global.GoCQReverseWebsocketConfig, authToken string, b *coolq.CQBot) *websocketClient { //NewWebSocketClient 初始化一个NWebSocket客户端
return &websocketClient{conf: conf, token: authToken, bot: b} func NewWebSocketClient(conf *global.GoCQReverseWebSocketConfig, authToken string, b *coolq.CQBot) *WebSocketClient {
return &WebSocketClient{conf: conf, token: authToken, bot: b}
} }
func (c *websocketClient) Run() { //Run 运行实例
func (c *WebSocketClient) Run() {
if !c.conf.Enabled { if !c.conf.Enabled {
return return
} }
if c.conf.ReverseUrl != "" { if c.conf.ReverseURL != "" {
c.connectUniversal() c.connectUniversal()
} else { } else {
if c.conf.ReverseApiUrl != "" { if c.conf.ReverseAPIURL != "" {
c.connectApi() c.connectAPI()
} }
if c.conf.ReverseEventUrl != "" { if c.conf.ReverseEventURL != "" {
c.connectEvent() c.connectEvent()
} }
} }
c.bot.OnEventPush(c.onBotPushEvent) c.bot.OnEventPush(c.onBotPushEvent)
} }
func (c *websocketClient) connectApi() { func (c *WebSocketClient) connectAPI() {
log.Infof("开始尝试连接到反向Websocket API服务器: %v", c.conf.ReverseApiUrl) log.Infof("开始尝试连接到反向Websocket API服务器: %v", c.conf.ReverseAPIURL)
header := http.Header{ header := http.Header{
"X-Client-Role": []string{"API"}, "X-Client-Role": []string{"API"},
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)}, "X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
@ -92,22 +96,22 @@ func (c *websocketClient) connectApi() {
if c.token != "" { if c.token != "" {
header["Authorization"] = []string{"Token " + c.token} header["Authorization"] = []string{"Token " + c.token}
} }
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseApiUrl, header) conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseAPIURL, header)
if err != nil { if err != nil {
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseApiUrl, err) log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseAPIURL, err)
if c.conf.ReverseReconnectInterval != 0 { if c.conf.ReverseReconnectInterval != 0 {
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval)) time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
c.connectApi() c.connectAPI()
} }
return return
} }
log.Infof("已连接到反向Websocket API服务器 %v", c.conf.ReverseApiUrl) log.Infof("已连接到反向Websocket API服务器 %v", c.conf.ReverseAPIURL)
wrappedConn := &websocketConn{Conn: conn} wrappedConn := &webSocketConn{Conn: conn}
go c.listenApi(wrappedConn, false) go c.listenAPI(wrappedConn, false)
} }
func (c *websocketClient) connectEvent() { func (c *WebSocketClient) connectEvent() {
log.Infof("开始尝试连接到反向Websocket Event服务器: %v", c.conf.ReverseEventUrl) log.Infof("开始尝试连接到反向Websocket Event服务器: %v", c.conf.ReverseEventURL)
header := http.Header{ header := http.Header{
"X-Client-Role": []string{"Event"}, "X-Client-Role": []string{"Event"},
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)}, "X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
@ -116,9 +120,9 @@ func (c *websocketClient) connectEvent() {
if c.token != "" { if c.token != "" {
header["Authorization"] = []string{"Token " + c.token} header["Authorization"] = []string{"Token " + c.token}
} }
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseEventUrl, header) conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseEventURL, header)
if err != nil { if err != nil {
log.Warnf("连接到反向Websocket Event服务器 %v 时出现错误: %v", c.conf.ReverseEventUrl, err) log.Warnf("连接到反向Websocket Event服务器 %v 时出现错误: %v", c.conf.ReverseEventURL, err)
if c.conf.ReverseReconnectInterval != 0 { if c.conf.ReverseReconnectInterval != 0 {
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval)) time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
c.connectEvent() c.connectEvent()
@ -133,12 +137,12 @@ func (c *websocketClient) connectEvent() {
log.Warnf("反向Websocket 握手时出现错误: %v", err) log.Warnf("反向Websocket 握手时出现错误: %v", err)
} }
log.Infof("已连接到反向Websocket Event服务器 %v", c.conf.ReverseEventUrl) log.Infof("已连接到反向Websocket Event服务器 %v", c.conf.ReverseEventURL)
c.eventConn = &websocketConn{Conn: conn} c.eventConn = &webSocketConn{Conn: conn}
} }
func (c *websocketClient) connectUniversal() { func (c *WebSocketClient) connectUniversal() {
log.Infof("开始尝试连接到反向Websocket Universal服务器: %v", c.conf.ReverseUrl) log.Infof("开始尝试连接到反向Websocket Universal服务器: %v", c.conf.ReverseURL)
header := http.Header{ header := http.Header{
"X-Client-Role": []string{"Universal"}, "X-Client-Role": []string{"Universal"},
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)}, "X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
@ -147,9 +151,9 @@ func (c *websocketClient) connectUniversal() {
if c.token != "" { if c.token != "" {
header["Authorization"] = []string{"Token " + c.token} header["Authorization"] = []string{"Token " + c.token}
} }
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseUrl, header) conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseURL, header)
if err != nil { if err != nil {
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseUrl, err) log.Warnf("连接到反向Websocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseURL, err)
if c.conf.ReverseReconnectInterval != 0 { if c.conf.ReverseReconnectInterval != 0 {
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval)) time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
c.connectUniversal() c.connectUniversal()
@ -164,12 +168,12 @@ func (c *websocketClient) connectUniversal() {
log.Warnf("反向Websocket 握手时出现错误: %v", err) log.Warnf("反向Websocket 握手时出现错误: %v", err)
} }
wrappedConn := &websocketConn{Conn: conn} wrappedConn := &webSocketConn{Conn: conn}
go c.listenApi(wrappedConn, true) go c.listenAPI(wrappedConn, true)
c.universalConn = wrappedConn c.universalConn = wrappedConn
} }
func (c *websocketClient) listenApi(conn *websocketConn, u bool) { func (c *WebSocketClient) listenAPI(conn *webSocketConn, u bool) {
defer conn.Close() defer conn.Close()
for { for {
_, buf, err := conn.ReadMessage() _, buf, err := conn.ReadMessage()
@ -184,12 +188,12 @@ func (c *websocketClient) listenApi(conn *websocketConn, u bool) {
if c.conf.ReverseReconnectInterval != 0 { if c.conf.ReverseReconnectInterval != 0 {
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval)) time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
if !u { if !u {
go c.connectApi() go c.connectAPI()
} }
} }
} }
func (c *websocketClient) onBotPushEvent(m coolq.MSG) { func (c *WebSocketClient) onBotPushEvent(m coolq.MSG) {
if c.eventConn != nil { if c.eventConn != nil {
log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJson()) log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJson())
conn := c.eventConn conn := c.eventConn
@ -222,7 +226,7 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) {
} }
} }
func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { func (s *webSocketServer) event(w http.ResponseWriter, r *http.Request) {
if s.token != "" { if s.token != "" {
if auth := r.URL.Query().Get("access_token"); auth != s.token { if auth := r.URL.Query().Get("access_token"); auth != s.token {
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token { if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
@ -246,14 +250,14 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) {
log.Infof("接受 Websocket 连接: %v (/event)", r.RemoteAddr) log.Infof("接受 Websocket 连接: %v (/event)", r.RemoteAddr)
conn := &websocketConn{Conn: c} conn := &webSocketConn{Conn: c}
s.eventConnMutex.Lock() s.eventConnMutex.Lock()
s.eventConn = append(s.eventConn, conn) s.eventConn = append(s.eventConn, conn)
s.eventConnMutex.Unlock() s.eventConnMutex.Unlock()
} }
func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { func (s *webSocketServer) api(w http.ResponseWriter, r *http.Request) {
if s.token != "" { if s.token != "" {
if auth := r.URL.Query().Get("access_token"); auth != s.token { if auth := r.URL.Query().Get("access_token"); auth != s.token {
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token { if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
@ -269,11 +273,11 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) {
return return
} }
log.Infof("接受 Websocket 连接: %v (/api)", r.RemoteAddr) log.Infof("接受 Websocket 连接: %v (/api)", r.RemoteAddr)
conn := &websocketConn{Conn: c} conn := &webSocketConn{Conn: c}
go s.listenApi(conn) go s.listenAPI(conn)
} }
func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { func (s *webSocketServer) any(w http.ResponseWriter, r *http.Request) {
if s.token != "" { if s.token != "" {
if auth := r.URL.Query().Get("access_token"); auth != s.token { if auth := r.URL.Query().Get("access_token"); auth != s.token {
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token { if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
@ -295,12 +299,12 @@ func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) {
return return
} }
log.Infof("接受 Websocket 连接: %v (/)", r.RemoteAddr) log.Infof("接受 Websocket 连接: %v (/)", r.RemoteAddr)
conn := &websocketConn{Conn: c} conn := &webSocketConn{Conn: c}
s.eventConn = append(s.eventConn, conn) s.eventConn = append(s.eventConn, conn)
s.listenApi(conn) s.listenAPI(conn)
} }
func (s *websocketServer) listenApi(c *websocketConn) { func (s *webSocketServer) listenAPI(c *webSocketConn) {
defer c.Close() defer c.Close()
for { for {
t, payload, err := c.ReadMessage() t, payload, err := c.ReadMessage()
@ -314,7 +318,7 @@ func (s *websocketServer) listenApi(c *websocketConn) {
} }
} }
func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) { func (c *webSocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Printf("处置WS命令时发生无法恢复的异常%v\n%s", err, debug.Stack()) log.Printf("处置WS命令时发生无法恢复的异常%v\n%s", err, debug.Stack())
@ -325,7 +329,7 @@ func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
j := gjson.ParseBytes(payload) j := gjson.ParseBytes(payload)
t := strings.ReplaceAll(j.Get("action").Str, "_async", "") t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw) log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
if f, ok := wsApi[t]; ok { if f, ok := wsAPI[t]; ok {
ret := f(bot, j.Get("params")) ret := f(bot, j.Get("params"))
if j.Get("echo").Exists() { if j.Get("echo").Exists() {
ret["echo"] = j.Get("echo").Value() ret["echo"] = j.Get("echo").Value()
@ -344,7 +348,7 @@ func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
} }
} }
func (s *websocketServer) onBotPushEvent(m coolq.MSG) { func (s *webSocketServer) onBotPushEvent(m coolq.MSG) {
s.eventConnMutex.Lock() s.eventConnMutex.Lock()
defer s.eventConnMutex.Unlock() defer s.eventConnMutex.Unlock()
for i, l := 0, len(s.eventConn); i < l; i++ { for i, l := 0, len(s.eventConn); i < l; i++ {
@ -368,7 +372,7 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
} }
} }
var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_login_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { "get_login_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetLoginInfo() return bot.CQGetLoginInfo()
}, },
@ -516,7 +520,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str) return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
}, },
"set_restart": func(c *coolq.CQBot, p gjson.Result) coolq.MSG { "set_restart": func(c *coolq.CQBot, p gjson.Result) coolq.MSG {
var delay int64 = 0 var delay int64
delay = p.Get("delay").Int() delay = p.Get("delay").Int()
if delay < 0 { if delay < 0 {
delay = 0 delay = 0