-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package entities | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/volcengine/datatester-go-sdk/distributor/bucketer" | ||
) | ||
|
||
type Domain struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
HashStrategy string `json:"hash_strategy"` | ||
Begin uint32 `json:"begin"` | ||
Length uint32 `json:"length"` | ||
} | ||
|
||
// Hit 方法检查给定的 decisionID 是否在当前 Domain 的索引范围内 | ||
func (d Domain) Hit(decisionID string) bool { | ||
// 通过连接 decisionID 和 d.Name 获取流量桶索引 | ||
index, err := bucketer.NewMmh3BucketService().GetTrafficBucketIndex( | ||
strings.Join([]string{decisionID, d.Name}, ":")) | ||
// 如果获取索引过程中出现错误,返回 false | ||
if err != nil { | ||
return false | ||
} | ||
// 如果索引值在 d.Begin 和 d.Begin + d.Length 之间,返回 true,否则返回 false | ||
return index >= d.Begin && index < d.Begin+d.Length | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters