add implementation to 'default types'

This commit is contained in:
Adrien Marquès 2018-10-01 14:02:09 +02:00
parent 17bb63b9de
commit fd6d7b661e
3 changed files with 45 additions and 14 deletions

View File

@ -9,6 +9,8 @@ import (
"time" "time"
) )
var defaultTypeFolder = filepath.Join(os.Getenv("GOPATH"), "src/git.xdrm.io/go/aicra/internal/checker/default/*")
func main() { func main() {
starttime := time.Now() starttime := time.Now()
@ -39,7 +41,36 @@ func main() {
return 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 { if len(schema.Types.Map) > 0 {
clifmt.Title("compile types") clifmt.Title("compile types")
for name, upath := range schema.Types.Map { 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 { if len(schema.Controllers.Map) > 0 {
clifmt.Title("compile controllers") clifmt.Title("compile controllers")
for name, upath := range schema.Controllers.Map { 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 { if len(schema.Middlewares.Map) > 0 {
clifmt.Title("compile middlewares") clifmt.Title("compile middlewares")
for name, upath := range schema.Middlewares.Map { for name, upath := range schema.Middlewares.Map {

View File

@ -6,17 +6,17 @@ var Default = Schema{
Port: 80, Port: 80,
DriverName: "", DriverName: "",
Types: &builder{ Types: &builder{
IgnoreBuiltIn: false, Default: true,
Folder: "", Folder: "",
Map: nil, Map: nil,
}, },
Controllers: &builder{ Controllers: &builder{
IgnoreBuiltIn: true, Default: false,
Folder: "", Folder: "",
Map: nil, Map: nil,
}, },
Middlewares: &builder{ Middlewares: &builder{
IgnoreBuiltIn: true, Default: false,
Folder: "", Folder: "",
Map: nil, Map: nil,
}, },

View File

@ -5,8 +5,8 @@ import (
) )
type builder struct { type builder struct {
// IgnoreBuiltIn tells whether or not to ignore the built-in components // Default tells whether or not to ignore the built-in components
IgnoreBuiltIn bool `json:"default,ommitempty"` Default bool `json:"default,ommitempty"`
// Folder is used to infer the 'Map' object // Folder is used to infer the 'Map' object
Folder string `json:"folder,ommitempty"` Folder string `json:"folder,ommitempty"`