dynamicdev

package
v0.0.0-...-365fcd0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 9 Imported by: 0

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

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

func ReadInFile(filePath string) (content string, err error)

used to read either go file or front end file

func SourceCodeToArchitecture

func SourceCodeToArchitecture(sourceCode string) (architecture string, err error)

Types

type CodeDelIn

type CodeDelIn struct {
	FileName string
}

type CodeDelOut

type CodeDelOut string

type CodeGetIn

type CodeGetIn struct {
	FileName string
}

type CodeGetOut

type CodeGetOut struct {
	SourceCode string
}

type CodePutIn

type CodePutIn struct {
	FileName   string
	SourceCode string
}

type CodePutOut

type CodePutOut struct {
	Architect  string
	SourceCode string
}

type CompileAndRunGoCodeIn

type CompileAndRunGoCodeIn struct {
	SourceCode string
	FileName   string
	RunOnce    bool
}

type GetProjectArchitectureInfoIn

type GetProjectArchitectureInfoIn struct {
	//default is current dir
	ProjectDir       string
	SkipDirs         []string
	SkipFiles        []string
	IncludedFileExts []string
}

type GetProjectArchitectureInfoOut

type GetProjectArchitectureInfoOut struct {
	BasePath     string
	RelName2Arch map[string]string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL