gitlab.com/evatix-go/core@v1.3.55/coredata/corepayload/SessionInfo.go (about) 1 package corepayload 2 3 import ( 4 "gitlab.com/evatix-go/core/constants" 5 "gitlab.com/evatix-go/core/converters" 6 ) 7 8 type SessionInfo struct { 9 Id string `json:"Id,omitempty"` 10 User *User `json:"User,omitempty"` 11 SessionPath string `json:"SessionPath,omitempty"` 12 } 13 14 // IdentifierInteger 15 // 16 // Invalid value returns constants.InvalidValue 17 func (it *SessionInfo) IdentifierInteger() int { 18 if it.Id == "" { 19 return constants.InvalidValue 20 } 21 22 idInt, _ := converters.StringToIntegerWithDefault( 23 it.Id, 24 constants.InvalidValue) 25 26 return idInt 27 } 28 29 // IdentifierUnsignedInteger 30 // 31 // Invalid value returns constants.Zero 32 func (it *SessionInfo) IdentifierUnsignedInteger() uint { 33 idInt := it.IdentifierInteger() 34 35 if idInt < 0 { 36 return constants.Zero 37 } 38 39 return uint(idInt) 40 } 41 42 func (it *SessionInfo) IsEmpty() bool { 43 return it == nil 44 } 45 46 func (it *SessionInfo) IsValid() bool { 47 return !it.IsEmpty() && it.Id != "" 48 } 49 50 func (it *SessionInfo) IsUserNameEmpty() bool { 51 return it == nil || it.User.IsNameEmpty() 52 } 53 54 func (it *SessionInfo) IsUserEmpty() bool { 55 return it == nil || it.User.IsEmpty() 56 } 57 58 func (it *SessionInfo) HasUser() bool { 59 return it != nil && it.User.IsValidUser() 60 } 61 62 func (it *SessionInfo) IsUsernameEqual( 63 name string, 64 ) bool { 65 return it != nil && 66 it.User.IsNameEqual(name) 67 } 68 69 func (it SessionInfo) Clone() SessionInfo { 70 return SessionInfo{ 71 Id: it.Id, 72 User: it.User.ClonePtr(), 73 SessionPath: it.SessionPath, 74 } 75 } 76 77 func (it *SessionInfo) ClonePtr() *SessionInfo { 78 if it == nil { 79 return nil 80 } 81 82 return it.Clone().Ptr() 83 } 84 85 func (it SessionInfo) Ptr() *SessionInfo { 86 return &it 87 }