package main import ( "os/exec" "strings" "golang.org/x/exp/slices" ) var CompileConfigs = []*CompileConfig{} type CompileConfig struct { OS string Arch string FileExt string Compress bool } func FillCompileConfigs() error { cmd := exec.Command("go", "tool", "dist", "list") systems := strings.Split(*OS, ",") arches := strings.Split(*Arch, ",") out, err := cmd.Output() if err != nil { return err } lines := strings.Split(strings.TrimSpace(string(out)), "\n") for _, line := range lines { splits := strings.Split(line, "/") os, arch := splits[0], splits[1] if (*OS != "" && !slices.Contains(systems, os)) || (*Arch != "" && !slices.Contains(arches, arch)) { continue } ext := "" if os == "windows" { ext = ".exe" } cfg := &CompileConfig{ OS: os, Arch: arch, Compress: true, FileExt: ext, } CompileConfigs = append(CompileConfigs, cfg) } return nil }