地址:https://github.com/KunBetter/ABTest
用法
```go
import (
"fmt"
"github.com/KunBetter/ABTest/core"
"io/ioutil"
)
func main() {
ab := &core.ABTest{}
ab.Init()
buf, err := ioutil.ReadFile("ABExpConfig.json")
if err != nil {
fmt.Print(err)
return
}
ab.LoadConfig([]string{string(buf)})
reqMap := make(map[string]string)
tagMap := ab.Distribute(reqMap)
fmt.Println(tagMap)
}
```
实验配置(ABExpConfig.json)
```json
{
"layid": 100,
"name": "test",
"divertkey": "random",
"defaulttag": "true",
"whitelistkey": "userid",
"conditions": {
"type": "1",
"id": "5"
},
"experiments": [
{
"expid": 1,
"traffic": 10,
"whitelists": [
"1",
"2",
"3"
],
"tag": "no",
"logtag": "no"
},
{
"expid": 2,
"traffic": 90,
"whitelists": [
"6",
"7",
"8"
],
"tag": "yes",
"logtag": "yes"
}
]
}
```
后面暂时定的规划是:
1、实验条件匹配支持多种运算符,不再是简单的相等判断
2、支持千分位流量切换实验,流量量级很大、实验成本较高时使用
有疑问加站长微信联系(非本文作者)