فهرست منبع

chore: 移除 panic,转移 cache 初始化到 Wechat 结构体方法下;在使用时可以只设置一次 cache 同时避免 panic 出现 (#668)

牛强 3 سال پیش
والد
کامیت
d6371c7289
2فایلهای تغییر یافته به همراه3 افزوده شده و 3 حذف شده
  1. 0 3
      openplatform/openplatform.go
  2. 3 0
      wechat.go

+ 0 - 3
openplatform/openplatform.go

@@ -18,9 +18,6 @@ type OpenPlatform struct {
 
 
 // NewOpenPlatform new openplatform
 // NewOpenPlatform new openplatform
 func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
 func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
-	if cfg.Cache == nil {
-		panic("cache 未设置")
-	}
 	ctx := &context.Context{
 	ctx := &context.Context{
 		Config: cfg,
 		Config: cfg,
 	}
 	}

+ 3 - 0
wechat.go

@@ -68,6 +68,9 @@ func (wc *Wechat) GetPay(cfg *payConfig.Config) *pay.Pay {
 
 
 // GetOpenPlatform 获取微信开放平台的实例
 // GetOpenPlatform 获取微信开放平台的实例
 func (wc *Wechat) GetOpenPlatform(cfg *openConfig.Config) *openplatform.OpenPlatform {
 func (wc *Wechat) GetOpenPlatform(cfg *openConfig.Config) *openplatform.OpenPlatform {
+	if cfg.Cache == nil {
+		cfg.Cache = wc.cache
+	}
 	return openplatform.NewOpenPlatform(cfg)
 	return openplatform.NewOpenPlatform(cfg)
 }
 }