github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/provider/golang.go (about) 1 /* Golang Compiler Provider 2 * (C) 2019 LanceLRQ 3 * 4 * This code is licenced under the GPLv3. 5 */ 6 package provider 7 8 import "fmt" 9 10 type GolangCompileProvider struct { 11 CodeCompileProvider 12 } 13 14 func NewGolangCompileProvider() *GolangCompileProvider { 15 return &GolangCompileProvider{ 16 CodeCompileProvider{ 17 isReady: false, 18 realTime: false, 19 Name: "golang", 20 }, 21 } 22 } 23 24 func (prov *GolangCompileProvider) Init(code string, workDir string) error { 25 prov.codeContent = code 26 prov.workDir = workDir 27 28 err := prov.checkWorkDir() 29 if err != nil { 30 return err 31 } 32 33 err = prov.initFiles(".go", "") 34 return err 35 } 36 37 func (prov *GolangCompileProvider) Compile() (result bool, errmsg string) { 38 result, errmsg = prov.shell(fmt.Sprintf(CompileCommands.Go, prov.programFilePath, prov.codeFilePath)) 39 if result { 40 prov.isReady = true 41 } 42 return 43 } 44 45 func (prov *GolangCompileProvider) GetRunArgs() (args []string) { 46 args = []string{prov.programFilePath} 47 return 48 } 49 50 func (prov *GolangCompileProvider) IsCompileError(remsg string) bool { 51 return false 52 } 53 54 // 手动编译 55 func (prov *GolangCompileProvider) ManualCompile(source string, target string) (bool, string) { 56 cmd := fmt.Sprintf(CompileCommands.Go, source, target) 57 result, err := prov.shell(cmd) 58 return result, err 59 }