gitlab.com/evatix-go/core@v1.3.55/coreinstruction/BaseUsername.go (about) 1 package coreinstruction 2 3 import ( 4 "regexp" 5 "strings" 6 7 "gitlab.com/evatix-go/core/internal/strutilinternal" 8 ) 9 10 type BaseUsername struct { 11 Username string `json:"Username"` 12 } 13 14 func NewUsername(user string) *BaseUsername { 15 return &BaseUsername{Username: user} 16 } 17 18 func (it *BaseUsername) UsernameString() string { 19 return it.Username 20 } 21 22 func (it *BaseUsername) IsUsernameEmpty() bool { 23 return it == nil || it.Username == "" 24 } 25 26 func (it *BaseUsername) IsUsernameWhitespace() bool { 27 return it == nil || strutilinternal.IsNullOrEmptyOrWhitespace(&it.Username) 28 } 29 30 func (it *BaseUsername) IsUsername(user string) bool { 31 return it.Username == user 32 } 33 34 func (it *BaseUsername) IsUsernameCaseInsensitive(usernameInsensitive string) bool { 35 return strings.EqualFold(it.Username, usernameInsensitive) 36 } 37 38 func (it *BaseUsername) IsUsernameContains(usernameContains string) bool { 39 return strings.Contains(it.Username, usernameContains) 40 41 } 42 43 func (it *BaseUsername) IsUsernameRegexMatches(regex *regexp.Regexp) bool { 44 return regex.MatchString(it.Username) 45 } 46 47 func (it *BaseUsername) IsEqual(right *BaseUsername) bool { 48 if it == nil && right == nil { 49 return true 50 } 51 52 if it == nil || right == nil { 53 return false 54 } 55 56 return it.Username == right.Username 57 } 58 59 func (it *BaseUsername) IsNotEqual(right *BaseUsername) bool { 60 return !it.IsEqual(right) 61 } 62 63 func (it *BaseUsername) ClonePtr() *BaseUsername { 64 if it == nil { 65 return nil 66 } 67 68 return &BaseUsername{ 69 Username: it.Username, 70 } 71 } 72 73 func (it BaseUsername) Clone() BaseUsername { 74 return BaseUsername{ 75 Username: it.Username, 76 } 77 }