Przeglądaj źródła

config如果没设Cache, 给一个默认的Cache

yaotian 8 lat temu
rodzic
commit
d7996014f1
1 zmienionych plików z 5 dodań i 0 usunięć
  1. 5 0
      wechat.go

+ 5 - 0
wechat.go

@@ -16,6 +16,8 @@ import (
 	"github.com/yaotian/gowechat/server"
 )
 
+var Cache cache.Cache
+
 // Wechat struct
 type Wechat struct {
 	Context *context.Context
@@ -34,6 +36,9 @@ type Config struct {
 func NewWechat(cfg *Config) *Wechat {
 	context := new(context.Context)
 	copyConfigToContext(cfg, context)
+	if cfg.Cache == nil {
+		cfg.Cache, _ = cache.NewCache("memory", `{"interval":60}`)
+	}
 	return &Wechat{context}
 }