Skip to content
Snippets Groups Projects
Select Git revision
  • d438212ec01aa4bfb7ca410a073f360cc0df1697
  • master default protected
  • dev
3 results

main.cpp

Blame
  • 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()
    }