gitlab.com/evatix-go/core@v1.3.55/ostype/Variation.go (about) 1 package ostype 2 3 import ( 4 "gitlab.com/evatix-go/core/coredata/corejson" 5 "gitlab.com/evatix-go/core/coreinterface/enuminf" 6 ) 7 8 type Variation byte 9 10 // https://stackoverflow.com/a/50117892 | https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63 11 // go tool dist list 12 const ( 13 Any Variation = iota 14 Unknown 15 Windows 16 Linux 17 DarwinOrMacOs 18 JavaScript 19 FreeBsd 20 NetBsd 21 OpenBsd 22 DragonFly 23 Android 24 Plan9 25 Solaris 26 Nacl 27 Illumos 28 IOs 29 Aix 30 ) 31 32 func (it Variation) AllNameValues() []string { 33 return basicEnumImplOsType.AllNameValues() 34 } 35 36 func (it Variation) OnlySupportedErr(names ...string) error { 37 return basicEnumImplOsType.OnlySupportedErr(names...) 38 } 39 40 func (it Variation) OnlySupportedMsgErr(message string, names ...string) error { 41 return basicEnumImplOsType.OnlySupportedMsgErr(message, names...) 42 } 43 44 func (it Variation) ValueUInt16() uint16 { 45 return uint16(it) 46 } 47 48 func (it Variation) IntegerEnumRanges() []int { 49 return basicEnumImplOsType.IntegerEnumRanges() 50 } 51 52 func (it Variation) MinMaxAny() (min, max interface{}) { 53 return basicEnumImplOsType.MinMaxAny() 54 } 55 56 func (it Variation) MinValueString() string { 57 return basicEnumImplOsType.MinValueString() 58 } 59 60 func (it Variation) MaxValueString() string { 61 return basicEnumImplOsType.MaxValueString() 62 } 63 64 func (it Variation) MaxInt() int { 65 return basicEnumImplOsType.MaxInt() 66 } 67 68 func (it Variation) MinInt() int { 69 return basicEnumImplOsType.MinInt() 70 } 71 72 func (it Variation) RangesDynamicMap() map[string]interface{} { 73 return basicEnumImplOsType.RangesDynamicMap() 74 } 75 76 func (it Variation) IsByteValueEqual(value byte) bool { 77 return byte(it) == value 78 } 79 80 func (it Variation) Format(format string) (compiled string) { 81 return basicEnumImplOsType.Format(format, it) 82 } 83 84 func (it Variation) IsEnumEqual(enum enuminf.BasicEnumer) bool { 85 return it.Value() == enum.ValueByte() 86 } 87 88 func (it *Variation) IsAnyEnumsEqual(enums ...enuminf.BasicEnumer) bool { 89 for _, enum := range enums { 90 if it.IsEnumEqual(enum) { 91 return true 92 } 93 } 94 95 return false 96 } 97 98 func (it Variation) IsNameEqual(name string) bool { 99 return it.Name() == name 100 } 101 102 func (it Variation) IsAnyNamesOf(names ...string) bool { 103 for _, name := range names { 104 if it.IsNameEqual(name) { 105 return true 106 } 107 } 108 109 return false 110 } 111 112 func (it Variation) IsValueEqual(value byte) bool { 113 return it.ValueByte() == value 114 } 115 116 func (it Variation) IsAnyValuesEqual(anyByteValues ...byte) bool { 117 for _, currentVal := range anyByteValues { 118 if it.IsValueEqual(currentVal) { 119 return true 120 } 121 } 122 123 return false 124 } 125 126 func (it Variation) ValueInt() int { 127 return int(it) 128 } 129 130 func (it Variation) ValueInt8() int8 { 131 return int8(it) 132 } 133 134 func (it Variation) ValueInt16() int16 { 135 return int16(it) 136 } 137 138 func (it Variation) ValueInt32() int32 { 139 return int32(it) 140 } 141 142 func (it Variation) ValueString() string { 143 return it.ToNumberString() 144 } 145 146 func (it Variation) IsValid() bool { 147 return it.Value() != 0 148 } 149 150 func (it Variation) IsInvalid() bool { 151 return it.Value() == 0 152 } 153 154 func (it Variation) IsByte(another byte) bool { 155 return it == Variation(another) 156 } 157 158 func (it Variation) IsAnyOperatingSystem() bool { 159 return Any == it 160 } 161 162 func (it Variation) Is(other Variation) bool { 163 return other == it 164 } 165 166 func (it Variation) IsAnyMatch(others ...Variation) bool { 167 for _, other := range others { 168 if other == it { 169 return true 170 } 171 } 172 173 return false 174 } 175 176 func (it Variation) IsStringsMatchAny(others ...string) bool { 177 for _, other := range others { 178 otherVariant := GetVariant(other) 179 180 if otherVariant == it { 181 return true 182 } 183 } 184 185 return false 186 } 187 188 // IsPossibleUnixGroup variation != Windows 189 func (it Variation) IsPossibleUnixGroup() bool { 190 return it != Windows 191 } 192 193 func (it Variation) IsLinuxOrMac() bool { 194 return it == Linux || it == DarwinOrMacOs 195 } 196 197 func (it Variation) Group() Group { 198 if it == Windows { 199 return WindowsGroup 200 } 201 202 if it == Android { 203 return AndroidGroup 204 } 205 206 return UnixGroup 207 } 208 209 func (it Variation) IsActualGroupUnix() bool { 210 return it.Group().IsUnix() 211 } 212 213 func (it Variation) IsWindows() bool { 214 return it == Windows 215 } 216 217 func (it Variation) IsLinux() bool { 218 return it == Linux 219 } 220 221 func (it Variation) IsDarwinOrMacOs() bool { 222 return it == DarwinOrMacOs 223 } 224 225 func (it Variation) IsJavaScript() bool { 226 return it == JavaScript 227 } 228 229 func (it Variation) IsFreeBsd() bool { 230 return it == FreeBsd 231 } 232 233 func (it Variation) IsNetBsd() bool { 234 return it == NetBsd 235 } 236 237 func (it Variation) IsOpenBsd() bool { 238 return it == NetBsd 239 } 240 241 func (it Variation) IsDragonFly() bool { 242 return it == DragonFly 243 } 244 245 func (it Variation) MarshalJSON() ([]byte, error) { 246 return basicEnumImplOsType.ToEnumJsonBytes(it.Value()) 247 } 248 249 func (it *Variation) UnmarshalJSON(data []byte) error { 250 valueByte, err := basicEnumImplOsType.UnmarshallToValue( 251 true, 252 data) 253 254 if err == nil { 255 *it = Variation(valueByte) 256 } 257 258 return err 259 } 260 261 func (it Variation) Name() string { 262 return basicEnumImplOsType.ToEnumString(it.Value()) 263 } 264 265 func (it Variation) GoosName() string { 266 return basicEnumImplOsType.ToEnumString(it.Value()) 267 } 268 269 func (it Variation) NameValue() string { 270 return basicEnumImplOsType.NameWithValue(it.Value()) 271 } 272 273 func (it Variation) ToNumberString() string { 274 return basicEnumImplOsType.ToNumberString(it.Value()) 275 } 276 277 func (it Variation) RangeNamesCsv() string { 278 return basicEnumImplOsType.RangeNamesCsv() 279 } 280 281 func (it Variation) TypeName() string { 282 return basicEnumImplOsType.TypeName() 283 } 284 285 func (it Variation) UnmarshallEnumToValue(jsonUnmarshallingValue []byte) (byte, error) { 286 return basicEnumImplOsType.UnmarshallToValue(true, jsonUnmarshallingValue) 287 } 288 289 func (it Variation) MaxByte() byte { 290 return basicEnumImplOsType.Max() 291 } 292 293 func (it Variation) MinByte() byte { 294 return basicEnumImplOsType.Min() 295 } 296 297 func (it Variation) ValueByte() byte { 298 return byte(it) 299 } 300 301 func (it Variation) RangesByte() []byte { 302 return basicEnumImplOsType.Ranges() 303 } 304 305 func (it Variation) Value() byte { 306 return byte(it) 307 } 308 309 func (it Variation) String() string { 310 return basicEnumImplOsType.ToEnumString(it.Value()) 311 } 312 313 func (it Variation) EnumType() enuminf.EnumTyper { 314 return basicEnumImplOsType.EnumType() 315 } 316 317 func (it Variation) AsBasicEnumContractsBinder() enuminf.BasicEnumContractsBinder { 318 return &it 319 } 320 321 func (it Variation) AsJsonContractsBinder() corejson.JsonMarshaller { 322 return &it 323 } 324 325 func (it Variation) AsBasicByteEnumContractsBinder() enuminf.BasicByteEnumContractsBinder { 326 return &it 327 } 328 329 func (it Variation) ToPtr() *Variation { 330 return &it 331 }