func (gapp *GoatApp) initArgsScope() error { gapp.argsScope = scope.Scope{ EventScope: scope.NewEventScope(), DataScope: scope.NewDataScope(map[string]interface{}{}), Injector: args.NewInjector(app.ArgsTagName), } return nil }
func (gapp *GoatApp) initEngineScope() error { gapp.argsScope = scope.Scope{ EventScope: scope.NewEventScope(), DataScope: scope.NewDataScope(map[string]interface{}{}), Injector: args.NewInjector(app.EngineTagName), } gapp.engineScope.Set(app.GoatVersion, app.GoatVersionValue) return nil }
// NewGoatApp create new app instance func NewGoatApp(name, version, basePath string) (*GoatApp, error) { gapp := &GoatApp{ name: name, version: version, } if err := gapp.initEngineScope(); err != nil { return nil, err } if err := gapp.initArgsScope(); err != nil { return nil, err } if err := gapp.initFilespaceScope(basePath); err != nil { return nil, err } if err := gapp.initConfigScope(); err != nil { return nil, err } if err := gapp.initDependencyScope(); err != nil { return nil, err } if err := gapp.initAppScope(); err != nil { return nil, err } if err := gapp.initCommandScope(); err != nil { return nil, err } dataScope := &scope.DataScope{ Data: make(map[string]interface{}), } gapp.globalScope = scope.Scope{ EventScope: scope.NewEventScope(), DataScope: dataScope, Injector: injector.NewMultiInjector([]app.Injector{ gapp.commandScope, gapp.appScope, gapp.dependencyScope, gapp.configScope, gapp.filespaceScope, gapp.argsScope, gapp.engineScope, dataScope.Injector(app.GlobalTagName), }), } gapp.globalScope.Set(app.EngineScope, gapp.engineScope) gapp.globalScope.Set(app.ArgsScope, gapp.argsScope) gapp.globalScope.Set(app.FilespaceScope, gapp.filespaceScope) gapp.globalScope.Set(app.ConfigScope, gapp.configScope) gapp.globalScope.Set(app.DependencyScope, gapp.dependencyScope) gapp.globalScope.Set(app.AppScope, gapp.appScope) gapp.globalScope.Set(app.CommandScope, gapp.commandScope) return gapp, nil }
func (gapp *GoatApp) initConfigScope() error { var fullmap map[string]interface{} json.ReadJSON(gapp.rootFilespace, ConfigJSONPath, fullmap) plainmap, err := plainmap.ToPlainMap(fullmap) if err != nil { return err } ds := &scope.DataScope{ Data: plainmap, } gapp.configScope = scope.Scope{ EventScope: scope.NewEventScope(), DataScope: ds, Injector: ds.Injector(app.ConfigTagName), } return nil }
// NewDependencyScope create new dependency scope func NewDependencyScope(tagname string) app.Scope { return DependencyScope{ EventScope: scope.NewEventScope(), DP: provider.NewProvider(tagname), } }