-
-
Save TKSS3/dde5491ba0d96ae8bff0b816dd4d9fbc to your computer and use it in GitHub Desktop.
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
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