Skip to content

Instantly share code, notes, and snippets.

@TKSS3

TKSS3/test.go Secret

Created March 19, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TKSS3/dde5491ba0d96ae8bff0b816dd4d9fbc to your computer and use it in GitHub Desktop.
Save TKSS3/dde5491ba0d96ae8bff0b816dd4d9fbc to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os/exec"
"runtime"
"golang.org/x/sys/windows/registry"
)
// OS is an interface for all OS's
type OS interface {
doSomething()
}
type windows struct{}
type linux struct{}
// WINDOWS
func (w windows) doSomething() {
regKey, err := registry.OpenKey(registry.CURRENT_USER, `Control Panel\Desktop`, registry.QUERY_VALUE)
if err != nil {
log.Fatal(err)
}
defer regKey.Close()
ssa, _, errSSA := regKey.GetStringValue("ScreenSaveActive")
if errSSA != nil {
log.Fatal(errSSA)
}
fmt.Printf("Screensaver is %q\n", ssa)
}
// LINUX
func (l linux) doSomething() {
out, err := exec.Command("uuidgen").Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", out)
}
// CHECK OS ON DEVICE POLICIES
func check(o OS) {
o.doSomething()
}
func main() {
switch os := runtime.GOOS; os {
case "windows":
osType := windows{}
check(osType)
case "linux":
osType := linux{}
check(osType)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment