package platformapi import ( "encoding/json" "fmt" "sort" "testing" "time" "git.rosy.net.cn/baseapi/utils" ) 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) } func Test_string_byte(t *testing.T) { //rankKey := map[string]string{"a": "刘磊", "b": "张雨绮%s", "c": "
下单时间:%s
"} //data, _ := json.Marshal(rankKey) dd := `{"a": "刘磊", "b": "张雨绮%s", "c": "
下单时间:%s
"}` var ee map[string]string err := json.Unmarshal([]byte(dd), ee) fmt.Println(err) fmt.Println("dd:", ee) }