From fd6d7b661ecf48fdb9a42b1d0902d9f99aa03d50 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 1 Oct 2018 14:02:09 +0200 Subject: [PATCH] add implementation to 'default types' --- cmd/aicra/main.go | 37 ++++++++++++++++++++++++++++++++++--- internal/meta/defaults.go | 18 +++++++++--------- internal/meta/types.go | 4 ++-- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/cmd/aicra/main.go b/cmd/aicra/main.go index 060d78c..1eb4c58 100644 --- a/cmd/aicra/main.go +++ b/cmd/aicra/main.go @@ -9,6 +9,8 @@ import ( "time" ) +var defaultTypeFolder = filepath.Join(os.Getenv("GOPATH"), "src/git.xdrm.io/go/aicra/internal/checker/default/*") + func main() { starttime := time.Now() @@ -39,7 +41,36 @@ func main() { return } - /* (2) Compile Types */ + /* (2) Compile Default Types */ + if schema.Types.Default { + clifmt.Title("compile default types") + files, err := filepath.Glob(defaultTypeFolder) + if err != nil { + fmt.Printf("cannot load default types") + } else { + + for _, file := range files { + + typeName, err := filepath.Rel(filepath.Dir(file), file) + if err != nil { + fmt.Printf("cannot load type '%s'\n", typeName) + continue + + } + + fmt.Printf(" [%s]\n", clifmt.Color(33, typeName)) + + // Get useful paths + source := filepath.Join(file, "main.go") + build := filepath.Join(schema.Root, ".build/type", fmt.Sprintf("%s.so", typeName)) + + compile(source, build) + } + + } + } + + /* (3) Compile Types */ if len(schema.Types.Map) > 0 { clifmt.Title("compile types") for name, upath := range schema.Types.Map { @@ -54,7 +85,7 @@ func main() { } } - /* (3) Compile controllers */ + /* (4) Compile controllers */ if len(schema.Controllers.Map) > 0 { clifmt.Title("compile controllers") for name, upath := range schema.Controllers.Map { @@ -70,7 +101,7 @@ func main() { } } - /* (4) Compile middlewares */ + /* (5) Compile middlewares */ if len(schema.Middlewares.Map) > 0 { clifmt.Title("compile middlewares") for name, upath := range schema.Middlewares.Map { diff --git a/internal/meta/defaults.go b/internal/meta/defaults.go index d820aa5..db23aea 100644 --- a/internal/meta/defaults.go +++ b/internal/meta/defaults.go @@ -6,18 +6,18 @@ var Default = Schema{ Port: 80, DriverName: "", Types: &builder{ - IgnoreBuiltIn: false, - Folder: "", - Map: nil, + Default: true, + Folder: "", + Map: nil, }, Controllers: &builder{ - IgnoreBuiltIn: true, - Folder: "", - Map: nil, + Default: false, + Folder: "", + Map: nil, }, Middlewares: &builder{ - IgnoreBuiltIn: true, - Folder: "", - Map: nil, + Default: false, + Folder: "", + Map: nil, }, } diff --git a/internal/meta/types.go b/internal/meta/types.go index 8e4c72a..53fcb98 100644 --- a/internal/meta/types.go +++ b/internal/meta/types.go @@ -5,8 +5,8 @@ import ( ) type builder struct { - // IgnoreBuiltIn tells whether or not to ignore the built-in components - IgnoreBuiltIn bool `json:"default,ommitempty"` + // Default tells whether or not to ignore the built-in components + Default bool `json:"default,ommitempty"` // Folder is used to infer the 'Map' object Folder string `json:"folder,ommitempty"`