1 Star 0 Fork 0

蒙蒙的男孩/polaris-go

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
hash.go 1.43 KB
Copy Edit Raw Blame History
蒙蒙的男孩 authored 2023-10-26 20:52 +08:00 . 添加调用方的实例ip属性
/**
* Tencent is pleased to support the open source community by making polaris-go available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package common
import (
"gitee.com/meng_mengs_boys/polaris-go/pkg/algorithm/hash"
"gitee.com/meng_mengs_boys/polaris-go/pkg/plugin/loadbalancer"
)
// CalcHashValue 计算hash值
func CalcHashValue(criteria *loadbalancer.Criteria, hashFunc hash.HashFuncWithSeed) (uint64, error) {
return CalcHashValueWithSeed(criteria, hashFunc, 0)
}
// CalcHashValueWithSeed 计算hash值
func CalcHashValueWithSeed(
criteria *loadbalancer.Criteria, hashFunc hash.HashFuncWithSeed, seed uint32) (uint64, error) {
var hashValue uint64
var err error
if len(criteria.HashKey) > 0 {
hashValue, err = hashFunc(criteria.HashKey, seed)
if err != nil {
return 0, err
}
} else {
hashValue = criteria.HashValue
}
return hashValue, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/meng_mengs_boys/polaris-go.git
git@gitee.com:meng_mengs_boys/polaris-go.git
meng_mengs_boys
polaris-go
polaris-go
v1.5.4

Search