Fix shadowed variables in various places: Part 1 of 2 (#10175)

* Fix shadowed variables in cmd package

* Fix shadowed variables in plugin package

* Fix shadowed variables in store package

* Fix shadowed variables in web package

* Changes as requested

Signed-off-by: Hanzei <hanzei@mailbox.org>

* Fix build

* Remove unnessary statements

* Use require all the time

* Fix build

* Rename variables according to feedback

* Fix NPE

* Changes as requested
Этот коммит содержится в:
Hanzei
2019-01-30 18:55:24 +01:00
коммит произвёл Jesse Hallam
родитель 2c9cf41dad
Коммит d898787371
6 изменённых файлов: 62 добавлений и 70 удалений

Просмотреть файл

@@ -151,14 +151,14 @@ func (env *Environment) Activate(id string) (manifest *model.Manifest, activated
return nil, false, fmt.Errorf("plugin not found: %v", id)
}
activePlugin := activePlugin{BundleInfo: pluginInfo}
ap := activePlugin{BundleInfo: pluginInfo}
defer func() {
if reterr == nil {
activePlugin.State = model.PluginStateRunning
ap.State = model.PluginStateRunning
} else {
activePlugin.State = model.PluginStateFailedToStart
ap.State = model.PluginStateFailedToStart
}
env.activePlugins.Store(pluginInfo.Manifest.Id, activePlugin)
env.activePlugins.Store(pluginInfo.Manifest.Id, ap)
}()
if pluginInfo.Manifest.MinServerVersion != "" {
@@ -211,11 +211,11 @@ func (env *Environment) Activate(id string) (manifest *model.Manifest, activated
}
if pluginInfo.Manifest.HasServer() {
supervisor, err := newSupervisor(pluginInfo, env.logger, env.newAPIImpl(pluginInfo.Manifest))
sup, err := newSupervisor(pluginInfo, env.logger, env.newAPIImpl(pluginInfo.Manifest))
if err != nil {
return nil, false, errors.Wrapf(err, "unable to start plugin: %v", id)
}
activePlugin.supervisor = supervisor
ap.supervisor = sup
componentActivated = true
}
@@ -236,12 +236,12 @@ func (env *Environment) Deactivate(id string) bool {
env.activePlugins.Delete(id)
activePlugin := p.(activePlugin)
if activePlugin.supervisor != nil {
if err := activePlugin.supervisor.Hooks().OnDeactivate(); err != nil {
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", activePlugin.BundleInfo.Manifest.Id), mlog.Err(err))
ap := p.(activePlugin)
if ap.supervisor != nil {
if err := ap.supervisor.Hooks().OnDeactivate(); err != nil {
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", ap.BundleInfo.Manifest.Id), mlog.Err(err))
}
activePlugin.supervisor.Shutdown()
ap.supervisor.Shutdown()
}
return true
@@ -250,13 +250,13 @@ func (env *Environment) Deactivate(id string) bool {
// Shutdown deactivates all plugins and gracefully shuts down the environment.
func (env *Environment) Shutdown() {
env.activePlugins.Range(func(key, value interface{}) bool {
activePlugin := value.(activePlugin)
ap := value.(activePlugin)
if activePlugin.supervisor != nil {
if err := activePlugin.supervisor.Hooks().OnDeactivate(); err != nil {
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", activePlugin.BundleInfo.Manifest.Id), mlog.Err(err))
if ap.supervisor != nil {
if err := ap.supervisor.Hooks().OnDeactivate(); err != nil {
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", ap.BundleInfo.Manifest.Id), mlog.Err(err))
}
activePlugin.supervisor.Shutdown()
ap.supervisor.Shutdown()
}
env.activePlugins.Delete(key)
@@ -270,9 +270,9 @@ func (env *Environment) Shutdown() {
// Consider using RunMultiPluginHook instead.
func (env *Environment) HooksForPlugin(id string) (Hooks, error) {
if p, ok := env.activePlugins.Load(id); ok {
activePlugin := p.(activePlugin)
if activePlugin.supervisor != nil {
return activePlugin.supervisor.Hooks(), nil
ap := p.(activePlugin)
if ap.supervisor != nil {
return ap.supervisor.Hooks(), nil
}
}
@@ -285,12 +285,12 @@ func (env *Environment) HooksForPlugin(id string) (Hooks, error) {
// plugins is not specified.
func (env *Environment) RunMultiPluginHook(hookRunnerFunc func(hooks Hooks) bool, hookId int) {
env.activePlugins.Range(func(key, value interface{}) bool {
activePlugin := value.(activePlugin)
ap := value.(activePlugin)
if activePlugin.supervisor == nil || !activePlugin.supervisor.Implements(hookId) {
if ap.supervisor == nil || !ap.supervisor.Implements(hookId) {
return true
}
if !hookRunnerFunc(activePlugin.supervisor.Hooks()) {
if !hookRunnerFunc(ap.supervisor.Hooks()) {
return false
}