Comments (2)
不好意思,上面写错了,应该是:
ival := reflect.ValueOf(c.TcpServer).Interface()
if val,ok := ival.(*Server);ok{
if val.OnConnStop!=nil{//这一句是判断用户有没有写钩子函数
c.Server.CallOnConnStop(c)
}
}
from zinx.
不错,用反射得到TcpServer是否有实体对象指向,然后再使用,这样、类型和野指针就都做了判断。 很感谢。
但是reflect会很耗性能,如果CallOnConnStop()这个函数,不经常被调用 你说的这种方式更好。
from zinx.
Related Issues (20)
- 请教一个关于多server的问题 HOT 1
- 生产环境下的log HOT 1
- connection.go can't use c.cancel() HOT 1
- 2个问题 HOT 2
- 请教一个问题
- Support http interface HOT 1
- websocket 可以支持 TextMessage格式吗 HOT 1
- 责任链(chain)代码疑问
- v1.1.1运行mmo_game_client出现报错,求指教w HOT 1
- 头部内容固定,脏数据不能处理,一直阻塞到半包 HOT 3
- [feat]: 配置参数可以通过环境变量覆盖 HOT 1
- 建议
- 建议handler里得方法增加context参数在第一位 HOT 1
- iconnection建议增加一addclosecallback接口和removeclosecallback接口。 HOT 3
- Connection的StartReader中读包的操作是不是错误的? HOT 1
- websocket并发写入问题 HOT 2
- [fix]文件名拼写错误 HOT 1
- 项目自定义 flag 参数不能解析 HOT 4
- ShardLockMaps的GetShard方法内应该使用结构体中的shareKeyFunc而非fnv32 HOT 2
- 目前版本又会出现#161 的问题? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zinx.