Skip to content

Commit

Permalink
Merge pull request #57 from projectdiscovery/issue-45-os-utils
Browse files Browse the repository at this point in the history
Addind os/arch utils
  • Loading branch information
Mzack9999 authored Jan 23, 2023
2 parents 688f9a6 + c08c628 commit ee9de8d
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
72 changes: 72 additions & 0 deletions os/arch.go
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"
}
81 changes: 81 additions & 0 deletions os/os.go
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"
}

0 comments on commit ee9de8d

Please sign in to comment.