gitlab.com/evatix-go/core@v1.3.55/chmodhelper/chmodins/RwxOwnerGroupOther.go (about) 1 package chmodins 2 3 import "gitlab.com/evatix-go/core/constants" 4 5 // RwxOwnerGroupOther 6 // 7 // Owner, Group, Other: 8 // String Index Values 9 // - 0: 'r'/'*'/'-' 10 // - 1: 'w'/'*'/'-' 11 // - 2: 'x'/'*'/'-' 12 // Examples can be : 13 // - "rwx" or 14 // - "*wx" or 15 // - "rw*" or 16 // - "***" 17 // 18 // Length must be 3. Not more not less. 19 type RwxOwnerGroupOther struct { 20 // String Index Values 21 // - 0: 'r'/'*'/'-' 22 // - 1: 'w'/'*'/'-' 23 // - 2: 'x'/'*'/'-' 24 // Examples can be : 25 // - "rwx" or 26 // - "*wx" or 27 // - "rw*" or 28 // - "***" 29 // 30 // Length must be 3. Not more not less. 31 Owner string `json:"Owner"` 32 // String Index Values 33 // - 0: 'r'/'*'/'-' 34 // - 1: 'w'/'*'/'-' 35 // - 2: 'x'/'*'/'-' 36 // Examples can be : 37 // - "rwx" or 38 // - "*wx" or 39 // - "rw*" or 40 // - "***" 41 // 42 // Length must be 3. Not more not less. 43 Group string `json:"Group"` 44 // String Index Values 45 // - 0: 'r'/'*'/'-' 46 // - 1: 'w'/'*'/'-' 47 // - 2: 'x'/'*'/'-' 48 // Examples can be : 49 // - "rwx" or 50 // - "*wx" or 51 // - "rw*" or 52 // - "***" 53 // 54 // Length must be 3. Not more not less. 55 Other string `json:"Other"` 56 } 57 58 // NewRwxOwnerGroupOther 59 // 60 // Each arg ownerRwx, groupRwx, otherRwx should have 61 // 62 // Index Values 63 // - 0: 'r'/'*'/'-' 64 // - 1: 'w'/'*'/'-' 65 // - 2: 'x'/'*'/'-' 66 // Examples can be : 67 // - "rwx" or 68 // - "*wx" or 69 // - "rw*" or 70 // - "***" 71 // 72 // Length must be 3. Not more not less. 73 func NewRwxOwnerGroupOther( 74 ownerRwx, 75 groupRwx, 76 otherRwx string, 77 ) *RwxOwnerGroupOther { 78 return &RwxOwnerGroupOther{ 79 Owner: ownerRwx, 80 Group: groupRwx, 81 Other: otherRwx, 82 } 83 } 84 85 func (receiver *RwxOwnerGroupOther) IsOwner(rwx string) bool { 86 return receiver.Owner == rwx 87 } 88 89 func (receiver *RwxOwnerGroupOther) IsGroup(rwx string) bool { 90 return receiver.Group == rwx 91 } 92 93 func (receiver *RwxOwnerGroupOther) IsOther(rwx string) bool { 94 return receiver.Other == rwx 95 } 96 97 func (receiver *RwxOwnerGroupOther) ExpandCharOwner() (r, w, x byte) { 98 return expandCharsRwx(receiver.Owner) 99 } 100 101 func (receiver *RwxOwnerGroupOther) ExpandCharGroup() (r, w, x byte) { 102 return expandCharsRwx(receiver.Group) 103 } 104 105 func (receiver *RwxOwnerGroupOther) ExpandCharOther() (r, w, x byte) { 106 return expandCharsRwx(receiver.Other) 107 } 108 109 func (receiver *RwxOwnerGroupOther) Is( 110 ownerRwx, 111 groupRwx, 112 otherRwx string, 113 ) bool { 114 return receiver.IsOwner(ownerRwx) && 115 receiver.IsGroup(groupRwx) && 116 receiver.IsOther(otherRwx) 117 } 118 119 func (receiver *RwxOwnerGroupOther) IsEqual(another *RwxOwnerGroupOther) bool { 120 if another == nil && receiver == nil { 121 return true 122 } 123 124 if another == nil || receiver == nil { 125 return false 126 } 127 128 return receiver.Owner == another.Owner && 129 receiver.Group == another.Group && 130 receiver.Other == another.Other 131 } 132 133 func (receiver *RwxOwnerGroupOther) ToString(isIncludeHyphen bool) string { 134 if isIncludeHyphen { 135 return receiver.String() 136 } 137 138 return receiver.Owner + 139 receiver.Group + 140 receiver.Other 141 } 142 143 // String : Includes hyphen in-front 144 // constants.Hyphen + 145 // receiver.Owner + 146 // receiver.Group + 147 // receiver.Other 148 func (receiver *RwxOwnerGroupOther) String() string { 149 return constants.Hyphen + 150 receiver.Owner + 151 receiver.Group + 152 receiver.Other 153 } 154 155 func (receiver *RwxOwnerGroupOther) Clone() *RwxOwnerGroupOther { 156 if receiver == nil { 157 return nil 158 } 159 160 return &RwxOwnerGroupOther{ 161 Owner: receiver.Owner, 162 Group: receiver.Group, 163 Other: receiver.Other, 164 } 165 }