package platformapi import ( "fmt" "sort" "testing" "time" "gitrosy.jxc4.com/baseapi/utils" ) func TestName(t *testing.T) { fmt.Println(1 | 2) fmt.Println(1 | 6) } func TestLimitSpeed(t *testing.T) { limiter := New(map[string]*LimiterConfig{ "limited1persecond": &LimiterConfig{ MaxAccessCount: 1, TimeGapMilliSecond: 1000, }, "limited10per10second": &LimiterConfig{ MaxAccessCount: 10, TimeGapMilliSecond: 10 * 1000, }, }, &LimiterConfig{ MaxAccessCount: 1, TimeGapMilliSecond: 2000, }) utils.CallFuncAsync(func() { count := 0 for { limiter.AccessAPI("limited1persecond", "") fmt.Printf("limited1persecond, time:%s, count:%d\n", time.Now().Format("2006-01-02 15:04:05.00000"), count) count++ } }) utils.CallFuncAsync(func() { count := 0 for { limiter.AccessAPI("limited10per10second", "") fmt.Printf("limited10per10second, time:%s, count:%d\n", time.Now().Format("2006-01-02 15:04:05.00000"), count) count++ } }) utils.CallFuncAsync(func() { count := 0 for { limiter.AccessAPI("otherAPI", "") fmt.Printf("otherAPI, time:%s, count:%d\n", time.Now().Format("2006-01-02 15:04:05.00000"), count) count++ } }) time.Sleep(30 * time.Second) } func Test_store(b *testing.T) { tempTagList := []int{1, 2, 3, 9, 5, 4} sort.Slice(tempTagList, func(i, j int) bool { if tempTagList[i] > tempTagList[j] { return false } return true }) fmt.Println(tempTagList) }