package main import ( "fmt" "git.aionnect.com/aionnect/go-common/utils" "strconv" ) func main() { newId, _ := utils.SingletonSnowflakeKeyGen().NextId() fmt.Printf("%v\n", utils.Decompose(newId)) println(len("oXnePxBaI4qUWq-X0HIU-ce6vgak")) //numCPU := runtime.NumCPU() //runtime.GOMAXPROCS(numCPU) //fmt.Println("number of cpu:", numCPU) // //consumer := make(chan utils.Long) // //const numID = 10000 //generate := func() { // for i := 0; i < numID; i++ { // consumer <- utils.NextId() // } //} // //const numGenerator = 10 //for i := 0; i < numGenerator; i++ { // go generate() //} // //set := mapset.NewSet() //for i := 0; i < numID*numGenerator; i++ { // id := <-consumer // if set.Contains(id) { // println("duplicated id") // return // } else { // set.Add(id) // } //} //fmt.Println("number of id:", set.Cardinality()) // 临时测试代码 //c, err := jws.NewJWT("hard to guess string"). // ParseToken("eyJhbGciOiJIUzI1NiIsImlhdCI6MTUzNzg0Njc4MywiZXhwIjoxNTM5MDU2MzgzfQ.eyJpZCI6MzI0NTEzNH0.RqRoad8H5oAGY6L3qMLcxCUYE5Fl7-MXtpSyfSU4aqU") //if nil != err { // println(err) //} //if nil != c { // fmt.Printf("%v\n", c) // fmt.Printf(strconv.FormatFloat(c.ID, 'f', 0, 64)) //} //n := 3 //for i := 0; i < 500; i++ { // newId, _ := utils.SingletonSnowflakeKeyGen().NextID() // // idStr := strconv.FormatUint(newId, 10) // sLen := len(idStr) // subLen:= sLen / n // if sLen % n != 0 { // subLen++ // } // // var partArr []string // var codeArr []string // for j := 0; j < n; j++ { // start := subLen * j // end := subLen * (j + 1) // if end >= sLen { // end = sLen // } // part := idStr[start:end] // partArr = append(partArr, part) // // partNum, _ := strconv.ParseInt(part, 10, 32) // code := decimalToAny(int(partNum), 35) // codeArr = append(codeArr, code) // } // // println(newId, " : ", strings.Join(partArr, "-"), " : ", strings.Join(codeArr, "-")) //} } var tenToAny = map[int]string{0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z", 36: ":", 37: ";", 38: "<", 39: "=", 40: ">", 41: "?", 42: "@", 43: "[", 44: "]", 45: "^", 46: "_", 47: "{", 48: "|", 49: "}", 50: "A", 51: "B", 52: "C", 53: "D", 54: "E", 55: "F", 56: "G", 57: "H", 58: "I", 59: "J", 60: "K", 61: "L", 62: "M", 63: "N", 64: "O", 65: "P", 66: "Q", 67: "R", 68: "S", 69: "T", 70: "U", 71: "V", 72: "W", 73: "X", 74: "Y", 75: "Z"} func decimalToAny(num int, n int) string { new_num_str := "" var remainder int var remainder_string string for num != 0 { remainder = num % n if 76 > remainder && remainder > 9 { remainder_string = tenToAny[remainder] } else { remainder_string = strconv.Itoa(remainder) } new_num_str = remainder_string + new_num_str num = num / n } return new_num_str }