···5 "strings"
6)
7000008func IsHandleNoAt(s string) bool {
9 // ref: https://atproto.com/specs/handle
10- re := regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
11- return re.MatchString(s)
12}
1314func UnflattenDid(s string) string {
···29 // Reconstruct as a standard DID format using Replace
30 // Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc"
31 reconstructed := strings.Replace(s, "-", ":", 2)
32- re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
3334- return re.MatchString(reconstructed)
35}
3637// FlattenDid converts a DID to a flattened format.
···4647// IsDid checks if the given string is a standard DID.
48func IsDid(s string) bool {
49- re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
50- return re.MatchString(s)
51}
···5 "strings"
6)
78+var (
9+ handleRegex = regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
10+ didRegex = regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
11+)
12+13func IsHandleNoAt(s string) bool {
14 // ref: https://atproto.com/specs/handle
15+ return handleRegex.MatchString(s)
016}
1718func UnflattenDid(s string) string {
···33 // Reconstruct as a standard DID format using Replace
34 // Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc"
35 reconstructed := strings.Replace(s, "-", ":", 2)
03637+ return didRegex.MatchString(reconstructed)
38}
3940// FlattenDid converts a DID to a flattened format.
···4950// IsDid checks if the given string is a standard DID.
51func IsDid(s string) bool {
52+ return didRegex.MatchString(s)
053}