-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from projectdiscovery/issue-45-os-utils
Addind os/arch utils
- Loading branch information
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package osutils | ||
|
||
import "runtime" | ||
|
||
type ArchType uint8 | ||
|
||
const ( | ||
I386 ArchType = iota | ||
Amd64 | ||
Amd64p32 | ||
Arm | ||
Armbe | ||
Arm64 | ||
Arm64be | ||
Loong64 | ||
Mips | ||
Mipsle | ||
Mips64 | ||
Mips64le | ||
Mips64p32 | ||
Mips64p32le | ||
Ppc | ||
Ppc64 | ||
Ppc64le | ||
Riscv | ||
Riscv64 | ||
S390 | ||
S390x | ||
Sparc | ||
Sparc64 | ||
Wasm | ||
UknownArch | ||
) | ||
|
||
var Arch ArchType | ||
|
||
func init() { | ||
switch { | ||
case Is386(): | ||
Arch = I386 | ||
case IsAmd64(): | ||
Arch = Amd64 | ||
case IsARM(): | ||
Arch = Arm | ||
case IsARM64(): | ||
Arch = Arm64 | ||
case IsWasm(): | ||
Arch = Wasm | ||
default: | ||
Arch = UknownArch | ||
} | ||
} | ||
|
||
func Is386() bool { | ||
return runtime.GOARCH == "386" | ||
} | ||
|
||
func IsAmd64() bool { | ||
return runtime.GOARCH == "amd64" | ||
} | ||
|
||
func IsARM() bool { | ||
return runtime.GOARCH == "arm" | ||
} | ||
|
||
func IsARM64() bool { | ||
return runtime.GOARCH == "arm64" | ||
} | ||
|
||
func IsWasm() bool { | ||
return runtime.GOARCH == "wasm" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package osutils | ||
|
||
import "runtime" | ||
|
||
type OsType uint8 | ||
|
||
const ( | ||
Darwin OsType = iota | ||
windows | ||
Linux | ||
Android | ||
IOS | ||
FreeBSD | ||
OpenBSD | ||
JS | ||
Solaris | ||
UnknownOS | ||
) | ||
|
||
var OS OsType | ||
|
||
func init() { | ||
switch { | ||
case IsOSX(): | ||
OS = Darwin | ||
case IsLinux(): | ||
OS = Linux | ||
case IsWindows(): | ||
OS = windows | ||
case IsAndroid(): | ||
OS = Android | ||
case IsIOS(): | ||
OS = IOS | ||
case IsJS(): | ||
OS = JS | ||
case IsFreeBSD(): | ||
OS = FreeBSD | ||
case IsOpenBSD(): | ||
OS = OpenBSD | ||
case IsSolaris(): | ||
OS = Solaris | ||
default: | ||
OS = UnknownOS | ||
} | ||
} | ||
|
||
func IsOSX() bool { | ||
return runtime.GOOS == "darwin" | ||
} | ||
|
||
func IsLinux() bool { | ||
return runtime.GOOS == "linux" | ||
} | ||
|
||
func IsWindows() bool { | ||
return runtime.GOOS == "windows" | ||
} | ||
|
||
func IsAndroid() bool { | ||
return runtime.GOOS == "android" | ||
} | ||
|
||
func IsIOS() bool { | ||
return runtime.GOOS == "ios" | ||
} | ||
|
||
func IsFreeBSD() bool { | ||
return runtime.GOOS == "freebsd" | ||
} | ||
|
||
func IsOpenBSD() bool { | ||
return runtime.GOOS == "openbsd" | ||
} | ||
|
||
func IsJS() bool { | ||
return runtime.GOOS == "js" | ||
} | ||
|
||
func IsSolaris() bool { | ||
return runtime.GOOS == "solaris" | ||
} |