🗑️ Deprecated FileHotReloadStorage
This commit is contained in:
parent
f395510f9a
commit
c378b6983c
14
bot_test.go
14
bot_test.go
@ -128,16 +128,4 @@ func TestSender(t *testing.T) {
|
|||||||
bot.Block()
|
bot.Block()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHotReloadStorage(t *testing.T) {
|
|
||||||
bot := DefaultBot(Desktop)
|
|
||||||
bot.MessageHandler = func(msg *Message) {
|
|
||||||
if msg.IsText() && msg.Content == "ping" {
|
|
||||||
msg.ReplyText("pong")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := bot.HotLogin(NewJsonFileHotReloadStorage("test.json")); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
bot.Block()
|
|
||||||
}
|
|
||||||
|
11
stroage.go
11
stroage.go
@ -1,7 +1,6 @@
|
|||||||
package openwechat
|
package openwechat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
@ -28,6 +27,7 @@ type HotReloadStorage io.ReadWriteCloser
|
|||||||
|
|
||||||
// JsonFileHotReloadStorage 实现HotReloadStorage接口
|
// JsonFileHotReloadStorage 实现HotReloadStorage接口
|
||||||
// 默认以json文件的形式存储
|
// 默认以json文件的形式存储
|
||||||
|
// Deprecated
|
||||||
type JsonFileHotReloadStorage struct {
|
type JsonFileHotReloadStorage struct {
|
||||||
FileName string
|
FileName string
|
||||||
file *os.File
|
file *os.File
|
||||||
@ -58,6 +58,9 @@ func (j *JsonFileHotReloadStorage) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewJsonFileHotReloadStorage 创建JsonFileHotReloadStorage
|
||||||
|
// Deprecated
|
||||||
|
// use os.File instead
|
||||||
func NewJsonFileHotReloadStorage(filename string) HotReloadStorage {
|
func NewJsonFileHotReloadStorage(filename string) HotReloadStorage {
|
||||||
return &JsonFileHotReloadStorage{FileName: filename}
|
return &JsonFileHotReloadStorage{FileName: filename}
|
||||||
}
|
}
|
||||||
@ -68,13 +71,9 @@ func NewHotReloadStorageItem(storage HotReloadStorage) (*HotReloadStorageItem, e
|
|||||||
if storage == nil {
|
if storage == nil {
|
||||||
return nil, errors.New("storage can't be nil")
|
return nil, errors.New("storage can't be nil")
|
||||||
}
|
}
|
||||||
var buffer bytes.Buffer
|
|
||||||
if _, err := buffer.ReadFrom(storage); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var item HotReloadStorageItem
|
var item HotReloadStorageItem
|
||||||
|
|
||||||
if err := json.NewDecoder(&buffer).Decode(&item); err != nil {
|
if err := json.NewDecoder(storage).Decode(&item); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &item, nil
|
return &item, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user