mqenergy / go-websocket Goto Github PK
View Code? Open in Web Editor NEW基于gorilla/websocket封装的websocket库,实现基于系统维度的消息推送,基于群组维度的消息推送,基于单个和多个客户端消息推送。
License: MIT License
基于gorilla/websocket封装的websocket库,实现基于系统维度的消息推送,基于群组维度的消息推送,基于单个和多个客户端消息推送。
License: MIT License
用的一个项目使用了这个包,启动的时候异常了,排查到问题是本地ip可能转换得到负数,除余1023仍然得到负数,然后snowflake约定初始值是0-1023导致panic项目直接启动不了。
// localIp得到负数情况下panic代码
Node, err = snowflake.NewNode(int64(localIp) % 1023)
if err != nil {
panic(err)
}
// 雪花算法抛出error逻辑
if n.node < 0 || n.node > n.nodeMax {
return nil, errors.New("Node number must be between 0 and " + strconv.FormatInt(n.nodeMax, 10))
}
如果确认是负数引起的问题,考虑解决方案
func GetLocalIpToInt() (uint32, error)
参考go的初学者,有个疑问,能否请教一下
type Hub struct { Clients map[*Client]bool ....
Hub 的Clients key是 *Client类型, value是个bool类型, 我看gorilla websocket chat example也是这样做的, 但是它是没有相关单客户推送的需求. 这是作者实现的单客户推送 是需要循环比对去取*Client,为什么不直接使用 map[int] *Client类型呢, key直接是snowflake产生的id, 还是经过权衡是原方式更有性能优势 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.