0

I have a go program in which I want to embed a binary for execute later. But since I need my program to be cross platform with the same codebase, I have two binaries (one for linux and one for windows).

I don't want to load both in memory, so I'm trying to embed only one of them, based on the value of runtime.GOOS.

The following code is non-sense but it will help you understand what I need.

runtimeOs := runtime.GOOS
if runtimeOs == "windows" {
    //go:embed vol.exe
    var volatilityWindows []byte
} else if runtimeOs == "linux" {
    //go:embed vol
    var volatilityLinux []byte
} else {
    fmt.Println("Unsupported operating system:", runtimeOs)
    os.Exit(1)
}
Mike Delta
  • 726
  • 2
  • 16
  • 32
  • 1
    Have multiple `.go` source files, with different build tags. Each file should embed the binary designated by OS of the build tag. – icza Feb 22 '23 at 09:03

0 Answers0