user.go (693B)
1 package internal 2 3 import ( 4 "errors" 5 ) 6 7 // User represents an application user. 8 // The username must be unique and contain only lowercase letters and digits. 9 type User struct { 10 ID int64 11 Username string 12 EncryptedPassword string 13 APIToken *string 14 } 15 16 // ValidateUsername verifies that the username is non-empty and contains only 17 // lowercase ASCII letters and digits. 18 func ValidateUsername(u string) error { 19 if u == "" { 20 return errors.New("username is required") 21 } 22 for i := 0; i < len(u); i++ { 23 c := u[i] 24 if (c < 'a' || c > 'z') && (c < '0' || c > '9') { 25 return errors.New("username must be lowercase letters and digits only") 26 } 27 } 28 return nil 29 }