gosal icon indicating copy to clipboard operation
gosal copied to clipboard

Implement OS Switch

Open bdemetris opened this issue 6 years ago • 3 comments

need to put a switch in that does something like

	switch os := runtime.GOOS; os {
	case "darwin":
		fmt.Println("darwin.")
	case "windows":
		fmt.Println("windows.")

bdemetris avatar Feb 04 '18 03:02 bdemetris

Example https://github.com/kolide/launcher/blob/fb08499f16d5fad96a545453f13ddfc2c70148cb/osquery/platform.go

groob avatar Feb 05 '18 01:02 groob

I've been thinking about this. What you want (most likely) is to use build tags to only compile windows code for exe and macos code for darwin binaries. Go has a quick shortcut for this. Basically any file that ends with _windows.go will only compile for windows and _darwin.go will only compile for mac. That can be used here by having a single function in reports like BuildReport() *Report which implemented three times in _darwin, _linux and _windows.go.

groob avatar Feb 07 '18 10:02 groob

Also agree about using the build tags. The file name approach is way more common and easier than using the // +windows header syntax.

That case statement might be required later but that’s only helpful for runtime vs buildtime.

clburlison avatar Feb 07 '18 12:02 clburlison