Documentation ¶
Overview ¶
Description: 1st: The client will upload source code in this API. 2nd: A file named {FileName}.tmp will be created. And the {FileName}.tmp will compared with the FileName specified In the input parameter using command line code diff <FileName> <FileName>.tmp 3rd: this vscode windows Will be focused to allow user to make revision
Index ¶
- Variables
- func ReadInFile(filePath string) (content string, err error)
- func SourceCodeToArchitecture(sourceCode string) (architecture string, err error)
- type CodeDelIn
- type CodeDelOut
- type CodeGetIn
- type CodeGetOut
- type CodePutIn
- type CodePutOut
- type CompileAndRunGoCodeIn
- type GetProjectArchitectureInfoIn
- type GetProjectArchitectureInfoOut
Constants ¶
This section is empty.
Variables ¶
View Source
var APICodeDel = api.Api(func(paramIn *CodeDelIn) (result CodeDelOut, err error) { if err = os.Remove(paramIn.FileName); err != nil { return "false", err } return "true", nil }).Func
View Source
var APICodeGet = api.Api(func(paramIn *CodeGetIn) (result *CodeGetOut, err error) { result = &CodeGetOut{} if result.SourceCode, err = ReadInFile(paramIn.FileName); err != nil { return nil, err } return result, nil }).Func
View Source
var APICodePut = api.Api(func(paramIn *CodePutIn) (architectures *CodePutOut, err error) { architectures = &CodePutOut{SourceCode: paramIn.SourceCode} if architectures.Architect, err = SourceCodeToArchitecture(paramIn.SourceCode); err != nil { return nil, err } if paramIn.SourceCode == "" || paramIn.FileName == "" { return architectures, nil } file, err := os.Create(paramIn.FileName) if err != nil { return nil, err } defer file.Close() _, err = file.WriteString(paramIn.SourceCode) if err != nil { return nil, err } return architectures, nil }).Func
View Source
var APIGetProjectArchitectureInfo = api.Api(func(packInfo *GetProjectArchitectureInfoIn) (architectures GetProjectArchitectureInfoOut, err error) { var surffixType = map[string]string{".go": "go", ".js": "js", ".ts": "js", ".vue": "js", ".jsx": "js", ".tsx": "js", ".html": "text", ".md": "text", ".json": "text", ".mdx": "text", ".toml": "text", ".txt": "text", "yaml": "text"} for _, surffix := range packInfo.IncludedFileExts { if len(surffix) == 0 { continue } else if surffix[0] != '.' { surffix = "." + surffix } surffixType[surffix] = "text" } architectures = GetProjectArchitectureInfoOut{ BasePath: dirOfDefaultProject, RelName2Arch: make(map[string]string), } if len(packInfo.ProjectDir) > 0 { architectures.BasePath = packInfo.ProjectDir } var skipDirs = map[string]bool{".vscode": true, "node_modules": true} for _, skippedDir := range packInfo.SkipDirs { skipDirs[skippedDir] = true } var skipFiles = map[string]bool{} for _, skipFile := range packInfo.SkipFiles { skipFiles[skipFile] = true } filepath.WalkDir(architectures.BasePath+"/.", func(path string, info os.DirEntry, err error) error { if err == filepath.SkipDir { return nil } if info.IsDir() { if skiodir, ok := skipDirs[info.Name()]; ok && skiodir { return filepath.SkipDir } return nil } else if skipfile, ok := skipFiles[info.Name()]; ok && skipfile { return nil } doctype, typeExisted := surffixType[filepath.Ext(path)] if !typeExisted { return nil } page, _ := ReadInFile(path) corrupted := false if doctype == "go" { _, err = parser.ParseFile(token.NewFileSet(), "", page, parser.ParseComments) corrupted = err != nil } RelName := path[len(architectures.BasePath):] architectures.RelName2Arch[RelName] = page if (doctype == "go" || doctype == "js") && !corrupted { architectures.RelName2Arch[RelName], _ = SourceCodeToArchitecture(page) } return nil }) return architectures, nil }).Func
View Source
var ApiCompileAndRunGoCode = api.Api(func(req *CompileAndRunGoCodeIn) (ok bool, err error) { tmpFile, err := os.CreateTemp("", "*.go") if err != nil { return false, err } defer os.Remove(tmpFile.Name()) if _, err := tmpFile.Write([]byte(req.FileName)); err != nil { return false, err } if err := tmpFile.Close(); err != nil { return false, err } outBinary := tmpFile.Name() + ".exe" cmdCompile := exec.Command("go", "build", "-o", outBinary, tmpFile.Name()) if err := cmdCompile.Run(); err != nil { return false, err } defer os.Remove(outBinary) cmdRun := exec.Command(outBinary) cmdRun.Stdout = os.Stdout cmdRun.Stderr = os.Stderr if err := cmdRun.Run(); err != nil { return false, err } return true, nil }).Func
Functions ¶
func ReadInFile ¶
used to read either go file or front end file
Types ¶
type CodeDelOut ¶
type CodeDelOut string
type CodeGetOut ¶
type CodeGetOut struct {
SourceCode string
}
type CodePutOut ¶
type CompileAndRunGoCodeIn ¶
Click to show internal directories.
Click to hide internal directories.