hyapp-server/pkg/xerr/device.go
2026-06-25 21:30:26 +08:00

37 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package xerr
import (
"fmt"
"strings"
)
// DeviceAlreadyRegisteredMessage 生成同设备注册达到上限时直接展示给 App 的错误文案。
// count 代表当前设备已注册账号数displayUserIDs 按原注册顺序列出短号,便于用户识别原账号。
func DeviceAlreadyRegisteredMessage(count int, displayUserIDs []string) string {
cleaned := make([]string, 0, len(displayUserIDs))
seen := make(map[string]struct{}, len(displayUserIDs))
for _, displayUserID := range displayUserIDs {
displayUserID = strings.TrimSpace(displayUserID)
if displayUserID == "" {
continue
}
if _, ok := seen[displayUserID]; ok {
continue
}
seen[displayUserID] = struct{}{}
cleaned = append(cleaned, displayUserID)
}
if count < len(cleaned) {
// 调用方如果只传了短号列表而没单独计数,展示数量必须至少覆盖实际列出的账号。
count = len(cleaned)
}
if count < 0 {
count = 0
}
if len(cleaned) == 0 {
return fmt.Sprintf("you device already register %d account, login failed", count)
}
return fmt.Sprintf("you device already register %d account %s, login failed", count, strings.Join(cleaned, ","))
}