This commit is contained in:
xxjwxc
2021-05-02 19:47:06 +08:00
parent 08a54c0722
commit 152bbd3f76
5 changed files with 37 additions and 34 deletions

View File

@@ -1,11 +1,10 @@
package mynsq
import (
"data/config"
"log"
"public/mylog"
"github.com/nsqio/go-nsq"
"github.com/xxjwxc/public/mylog"
)
var producer *nsq.Producer = nil
@@ -13,15 +12,15 @@ var consumerMap map[int]*nsq.Consumer = nil
var cosumerTopics map[string][]int = nil
func init() {
consumerMap = make(map[int]*nsq.Consumer)
cosumerTopics = make(map[string][]int)
cnf := nsq.NewConfig()
var err error
producer, err = nsq.NewProducer(config.GetNsqAddr(), cnf)
if err != nil {
mylog.Error(err)
panic(err)
}
// consumerMap = make(map[int]*nsq.Consumer)
// cosumerTopics = make(map[string][]int)
// cnf := nsq.NewConfig()
// var err error
// producer, err = nsq.NewProducer(config.GetNsqAddr(), cnf)
// if err != nil {
// mylog.Error(err)
// panic(err)
// }
}
@@ -30,13 +29,13 @@ func ProduceMsg(topic string, message []byte) bool {
if producer == nil {
//channel 锁住
cnf := nsq.NewConfig()
var err error
producer, err = nsq.NewProducer(config.GetNsqAddr(), cnf)
if err != nil {
mylog.Error(err)
return false
}
// cnf := nsq.NewConfig()
// var err error
// producer, err = nsq.NewProducer(config.GetNsqAddr(), cnf)
// if err != nil {
// mylog.Error(err)
// return false
// }
}
if producer != nil {

View File

@@ -48,11 +48,12 @@ func WriteData(pathExp string, clientid string, body ClientBody) bool {
}
cache := mycache.NewCache("websocket" + pathExp)
tp, b := cache.Value(clientid)
var tp []*websocket.Conn
e := cache.Value(clientid, &tp)
if b {
if e == nil {
b_r := false
tmp := tp.([]*websocket.Conn)
tmp := tp
for i := 0; i < len(tmp); i++ {
if _, err = tmp[i].Write(wb); err != nil {
mylog.Debug("Can't send", err.Error())
@@ -108,9 +109,10 @@ func InitWebSocket(pathExp string, handlerFunc HandlerReadFunc, stateFunc Handle
mutex.Lock()
tp, b := cache.Value(clientid)
if b && isMult { //多用户
tmp = tp.([]*websocket.Conn)
var tp []*websocket.Conn
b := cache.Value(clientid, &tp)
if b == nil && isMult { //多用户
tmp = tp
}
tmp = append(tmp, ws)
@@ -174,9 +176,11 @@ func InitWebSocket(pathExp string, handlerFunc HandlerReadFunc, stateFunc Handle
var tmp []*websocket.Conn
mutex.Lock()
tp, b := cache.Value(clientid)
if b {
tmp = tp.([]*websocket.Conn)
var tp []*websocket.Conn
b := cache.Value(clientid, &tp)
if b == nil {
tmp = tp
}
i := 0
for ; i < len(tmp); i++ {

View File

@@ -18,10 +18,10 @@ func NewGocache(server string) *Gocache {
}
//Get return cached value
func (mem *Gocache) Get(key string) interface{} {
v, _ := mem.mc.Value(key)
return v
}
// func (mem *Gocache) Get(key string) interface{} {
// v, _ := mem.mc.Value(key)
// return v
// }
// IsExist check value exists in memcache.
func (mem *Gocache) IsExist(key string) bool {

View File

@@ -144,7 +144,7 @@ func (_wx *wxTools) SendTemplateMsg(msg TempMsg) bool {
}
bo, _ := json.Marshal(msg)
resb := myhttp.OnPostJSON(_getSubscribe+accessToken, string(bo))
resb, _ := myhttp.OnPostJSON(_getSubscribe+accessToken, string(bo))
var res ResTempMsg
json.Unmarshal(resb, &res)

View File

@@ -22,7 +22,7 @@ func (_wx *wxTools) GetShareQrcode(path string, scene, page string) (ret QrcodeR
accessToken, _ := _wx.GetAccessToken() // 获取access_token
data := wxPostdata{Scene: scene, Page: page}
bo, _ := json.Marshal(data)
resb := myhttp.OnPostJSON(GETSHAREURL+accessToken, string(bo))
resb, _ := myhttp.OnPostJSON(GETSHAREURL+accessToken, string(bo))
tools.JSONEncode(string(resb), &ret) //错误码45029 最大限制
if ret.Errcode == 0 {
@@ -43,7 +43,7 @@ func (_wx *wxTools) GetWxQrcode(path, page string, width int) (ret QrcodeRet) {
data := wxQrcodedata{Path: page, Width: width}
bo, _ := json.Marshal(data)
resb := myhttp.OnPostJSON(GETQRCODEURL+accessToken, string(bo))
resb, _ := myhttp.OnPostJSON(GETQRCODEURL+accessToken, string(bo))
tools.JSONEncode(string(resb), &ret) //错误码45029 最大限制
if ret.Errcode == 0 {