diff --git a/cmd/aicra/build-controllers.go b/cmd/aicra/build-controllers.go deleted file mode 100644 index 9309d86..0000000 --- a/cmd/aicra/build-controllers.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "fmt" - "git.xdrm.io/go/aicra/clifmt" - "os" - "os/exec" - "path/filepath" - "strings" -) - -// Builds controllers as plugins (.so) -// from the sources in the @in folder -// recursively and generate .so files -// into the @out folder with the same structure -func buildControllers(in string, out string) error { - - /* (1) Create build folder */ - clifmt.Align(" . create output folder") - err := os.MkdirAll(out, os.ModePerm) - if err != nil { - return err - } - fmt.Printf("ok\n") - - /* (1) List recursively */ - sources := []string{} - err = filepath.Walk(in, func(path string, f os.FileInfo, err error) error { - if strings.HasSuffix(path, "i.go") { - sources = append(sources, path) - } - return nil - }) - - if err != nil { - return err - } - - /* (2) Print files */ - for _, infile := range sources { - - // 1. process output file name - rel, _ := filepath.Rel(in, infile) - outfile := strings.Replace(rel, ".go", ".so", 1) - outfile = fmt.Sprintf("%s/%s", out, outfile) - - clifmt.Align(fmt.Sprintf(" . compile %s", clifmt.Color(33, rel))) - - // 3. compile - stdout, err := exec.Command("go", - "build", "-buildmode=plugin", - "-o", outfile, - infile, - ).Output() - - // 4. success - if err == nil { - fmt.Printf("ok\n") - continue - } - - // 5. debug error - fmt.Printf("error\n") - if len(stdout) > 0 { - fmt.Printf("%s\n%s\n%s\n", clifmt.Color(31, "-=-"), stdout, clifmt.Color(31, "-=-")) - } - - } - - return nil -} diff --git a/cmd/aicra/build-types.go b/cmd/aicra/compile.go similarity index 96% rename from cmd/aicra/build-types.go rename to cmd/aicra/compile.go index 24ca7a4..ba82330 100644 --- a/cmd/aicra/build-types.go +++ b/cmd/aicra/compile.go @@ -13,7 +13,7 @@ import ( // from the sources in the @in folder // recursively and generate .so files // into the @out folder with the same structure -func buildTypes(in string, out string) error { +func compile(in string, out string) error { /* (1) Create build folder */ clifmt.Align(" . create output folder") diff --git a/cmd/aicra/main.go b/cmd/aicra/main.go index 9df6442..3abcba2 100644 --- a/cmd/aicra/main.go +++ b/cmd/aicra/main.go @@ -152,7 +152,7 @@ func main() { /* (2) Compile controllers */ if compileControllers { clifmt.Title("compile controllers") - err = buildControllers(cPath, filepath.Join(projectPath, ".build/controller")) + err = compile(cPath, filepath.Join(projectPath, ".build/controller")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } @@ -161,7 +161,7 @@ func main() { /* (3) Compile middlewares */ if compileMiddlewares { clifmt.Title("compile middlewares") - err = buildTypes(mPath, filepath.Join(projectPath, ".build/middleware")) + err = compile(mPath, filepath.Join(projectPath, ".build/middleware")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } @@ -169,16 +169,14 @@ func main() { /* (4) Compile DEFAULT types */ clifmt.Title("compile default types") - err = buildTypes( - dtPath, - filepath.Join(projectPath, ".build/type")) + err = compile(dtPath, filepath.Join(projectPath, ".build/type")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } /* (5) Compile types */ if compileTypes { clifmt.Title("compile types") - err = buildTypes(tPath, filepath.Join(projectPath, ".build/type")) + err = compile(tPath, filepath.Join(projectPath, ".build/type")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } diff --git a/request/request.go b/request/request.go index 26e8eb4..824d282 100644 --- a/request/request.go +++ b/request/request.go @@ -98,9 +98,9 @@ func (i *Request) LoadController(method string) (func(implement.Arguments, *impl /* (1) Build controller path */ path := strings.Join(i.Path, "-") if len(path) == 0 { - path = fmt.Sprintf(".build/controller/ROOT/main.so") + path = fmt.Sprintf(".build/controller/ROOT.so") } else { - path = fmt.Sprintf(".build/controller/%s/main.so", path) + path = fmt.Sprintf(".build/controller/%s.so", path) } /* (2) Format url */