fix 修复潜在索引越限问题

This commit is contained in:
孟帅 2024-05-09 11:25:05 +08:00
parent dc20a86b33
commit 817482bedb
2 changed files with 4 additions and 2 deletions

View File

@ -75,7 +75,9 @@ func GenHashOption(key interface{}, label string) *model.Option {
tag := "default" tag := "default"
if _, err := hash.Write(gconv.Bytes(label)); err == nil { if _, err := hash.Write(gconv.Bytes(label)); err == nil {
index := int(hash.Sum32()) % len(strings) index := int(hash.Sum32()) % len(strings)
tag = strings[index] if index < len(strings) {
tag = strings[index]
}
} }
return &model.Option{ return &model.Option{
Key: key, Key: key,

View File

@ -89,7 +89,7 @@ func (m *MsgParser) RegisterRPCRouter(routers ...interface{}) (err error) {
// RegisterInterceptor 注册拦截器 // RegisterInterceptor 注册拦截器
func (m *MsgParser) RegisterInterceptor(interceptors ...Interceptor) { func (m *MsgParser) RegisterInterceptor(interceptors ...Interceptor) {
m.interceptors = append(interceptors, interceptors...) m.interceptors = append(m.interceptors, interceptors...)
} }
// Encoding 消息编码 // Encoding 消息编码