-
Notifications
You must be signed in to change notification settings - Fork 0
/
runnerGen.go
34 lines (29 loc) · 883 Bytes
/
runnerGen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package runners
import (
"bytes"
"io/fs"
"io/ioutil"
"path/filepath"
)
type runnerGen struct {
langCommand string
className string
headerCode string
footerCode string
}
// Setups up a runner file for the provided runner.
// Returns the command to run this code, the fileName of the code, and an error
// if the error != nil the other return values will be ""
func (runner *runnerGen) CreateFile(code string, destination string) (string, string, error) {
outFileName := filepath.Join(destination, runner.className)
var permissionCode fs.FileMode = 0755
var codeBuffer bytes.Buffer
codeBuffer.WriteString(runner.headerCode)
codeBuffer.WriteString(code)
codeBuffer.WriteString(runner.footerCode)
err := ioutil.WriteFile(outFileName, codeBuffer.Bytes(), permissionCode)
if err != nil {
return "", "", err
}
return runner.langCommand, runner.className, nil
}