Select Git revision
-
Zohaib Butt authoredZohaib Butt authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
go_compiler.go 813 B
package go_compiler_v2
import (
"compiler_V2/consts"
"compiler_V2/utils"
"os"
)
const fileName = "main.go"
type GoCompiler struct{}
func NewGoCompiler() *GoCompiler {
return &GoCompiler{}
}
func (gb *GoCompiler) CheckCompileErrors(srcCode []byte) ([]byte, error) {
// Make temp folders
utils.SetupTempFolders(consts.TempOutputDir)
defer utils.RemoveTempFolders(consts.TempOutputDir)
// Write code to file
err := os.WriteFile(consts.TempOutputDir+fileName, srcCode, 0644)
if err != nil {
return nil, err
}
// Init go mod and tidy
cmdString := "go mod init tempOutput && go mod tidy "
// Run go build
cmdString += " && go build -o main " + fileName
//cmdSlice := strings.Fields(cmdString)
cmd := utils.MakeCommand(cmdString)
cmd.Dir = consts.TempOutputDir
return cmd.CombinedOutput()
}