package utils import ( "errors" "fmt" "sort" "strconv" ) func CombineId(aid, bid string) string { ids := []string{aid, bid} sort.Slice(ids, func(i, j int) bool { a, _ := strconv.ParseUint(ids[i], 0, 64) b, _ := strconv.ParseUint(ids[j], 0, 64) return a < b }) return fmt.Sprintf("%s_%s", ids[0], ids[1]) } func CombineUserID(aid, bid int64) string { ids := []int64{aid, bid} sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] }) return fmt.Sprintf("%s%s", fmt.Sprintf("%012x", ids[0]), fmt.Sprintf("%012x", ids[1])) } func UserIdToHex(id int64) string { return fmt.Sprintf("%012x", id) } func HexToUID(hex string) (int64, error) { var originalID int _, err := fmt.Sscanf(hex, "%x", &originalID) if err != nil { return int64(originalID), errors.New("用户id回转失败") } return int64(originalID), nil }