MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / emailToUsername

Function emailToUsername

internal/payment/webhook.go:461–477  ·  view source on GitHub ↗
(email string)

Source from the content-addressed store, hash-verified

459}
460
461func emailToUsername(email string) string {
462 parts := strings.SplitN(email, "@", 2)
463 name := parts[0]
464 // 只保留字母、数字、连字符、下划线、点
465 var b strings.Builder
466 for _, c := range name {
467 if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.' {
468 b.WriteRune(c)
469 }
470 }
471 result := b.String()
472 if result == "" {
473 // 8 字节 hex(64 bits 熵)确保唯一性
474 result = "user-" + randomHex(8)
475 }
476 return result
477}
478
479func randomHex(n int) string {
480 buf := make([]byte, n)

Callers 1

provisionNewUserMethod · 0.85

Calls 2

randomHexFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected