Init() now takes a TypeRegistry as 2nd arg, if NIL, use default settings (./types/*.so)"

This commit is contained in:
Adrien Marquès 2018-05-24 15:54:36 +02:00
parent 812831a665
commit a777de0096
3 changed files with 27 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.so
/types
/test

View File

@ -1,9 +1,18 @@
package gfw
import "git.xdrm.io/gfw/internal/config"
import (
"git.xdrm.io/gfw/checker"
"git.xdrm.io/gfw/internal/config"
)
// Init initilises a new framework instance
func Init(path string) (*Server, error) {
//
// - path is the configuration path
//
// - if typeChecker is nil, defaults will be used (all *.so files
// inside ./types local directory)
//
func Init(path string, typeChecker *checker.TypeRegistry) (*Server, error) {
/* (1) Init instance */
inst := &Server{
@ -19,5 +28,14 @@ func Init(path string) (*Server, error) {
}
inst.config = config
/* (3) Store registry if not nil */
if typeChecker != nil {
inst.Checker = typeChecker
return inst, nil
}
/* (4) Default registry creation */
inst.Checker = checker.CreateRegistry(true)
return inst, nil
}

View File

@ -1,12 +1,14 @@
package gfw
import (
"git.xdrm.io/gfw/checker"
"git.xdrm.io/gfw/internal/config"
)
type Server struct {
config *config.Controller
Params map[string]interface{}
Checker *checker.TypeRegistry // type check
err Err
}