airbnb / gosal

A Sal client written in Go
Apache License 2.0
35 stars 21 forks source link

Implement OS Switch #23

Open bdemetris opened 6 years ago

bdemetris commented 6 years ago

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.")
groob commented 6 years ago

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

groob commented 6 years ago

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.

clburlison commented 6 years ago

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.