Skip to content

Commit

Permalink
fix(v0.1.4-beta):Repair partial naming
Browse files Browse the repository at this point in the history
  • Loading branch information
tan-zhuo committed Feb 7, 2024
1 parent bd4b230 commit 9f898c3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions app/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func (m *DefaultLynxPluginManager) PreparePlug(config config.Config) []string {
}

for _, name := range names {
if _, exists := m.plugMap[name]; !exists && m.factory.Exists(name) {
if _, exists := m.pluginMap[name]; !exists && m.factory.Exists(name) {
p, err := m.factory.CreateByName(name)
if err != nil {
Lynx().Helper().Errorf("Plugin factory load error: %v", err)
panic(err)
}
m.plugins = append(m.plugins, p)
m.plugMap[p.Name()] = p
m.pluginList = append(m.pluginList, p)
m.pluginMap[p.Name()] = p
plugNames = append(plugNames, name)
}
}
Expand Down
30 changes: 15 additions & 15 deletions app/lynx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ var (
)

type LynxApp struct {
host string
name string
version string
cert Cert
logger log.Logger
globalConf config.Config
controlPlane ControlPlane
plugManager LynxPluginManager
host string
name string
version string
cert Cert
logger log.Logger
globalConf config.Config
controlPlane ControlPlane
pluginManager LynxPluginManager

dfLog *log.Helper
}
Expand Down Expand Up @@ -52,20 +52,20 @@ func NewApp(c config.Config, p ...plugin.Plugin) *LynxApp {
}

var app = &LynxApp{
host: host,
name: bootConf.Lynx.Application.Name,
version: bootConf.Lynx.Application.Version,
globalConf: c,
plugManager: NewLynxPluginManager(p...),
controlPlane: &LocalControlPlane{},
host: host,
name: bootConf.Lynx.Application.Name,
version: bootConf.Lynx.Application.Version,
globalConf: c,
pluginManager: NewLynxPluginManager(p...),
controlPlane: &LocalControlPlane{},
}
// The lynxApp is in Singleton pattern
lynxApp = app
return app
}

func (a *LynxApp) PlugManager() LynxPluginManager {
return a.plugManager
return a.pluginManager
}

func (a *LynxApp) GlobalConfig() config.Config {
Expand Down
40 changes: 20 additions & 20 deletions app/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ type LynxPluginManager interface {
}

type DefaultLynxPluginManager struct {
plugMap map[string]plugin.Plugin
plugins []plugin.Plugin
factory factory.PluginFactory
pluginMap map[string]plugin.Plugin
pluginList []plugin.Plugin
factory factory.PluginFactory
}

func NewLynxPluginManager(p ...plugin.Plugin) LynxPluginManager {
m := &DefaultLynxPluginManager{
plugins: make([]plugin.Plugin, 0),
factory: factory.GlobalPluginFactory(),
plugMap: make(map[string]plugin.Plugin),
pluginList: make([]plugin.Plugin, 0),
factory: factory.GlobalPluginFactory(),
pluginMap: make(map[string]plugin.Plugin),
}

// Manually set plugins
// Manually set pluginList
if p != nil && len(p) > 1 {
m.plugins = append(m.plugins, p...)
m.pluginList = append(m.pluginList, p...)
for i := 0; i < len(p); i++ {
m.plugMap[p[i].Name()] = p[i]
m.pluginMap[p[i].Name()] = p[i]
}
}
return m
Expand Down Expand Up @@ -102,7 +102,7 @@ func (m *DefaultLynxPluginManager) TopologicalSort(plugins []plugin.Plugin) ([]P
}
}

// Sort plugins with the same level by weight.
// Sort pluginList with the same level by weight.
sort.SliceStable(result, func(i, j int) bool {
if result[i].level == result[j].level {
return result[i].Weight() > result[j].Weight()
Expand All @@ -123,9 +123,9 @@ func contains(slice []PluginWithLevel, item plugin.Plugin) bool {
}

func (m *DefaultLynxPluginManager) LoadPlugins(conf config.Config) {
plugins, err := m.TopologicalSort(m.plugins)
plugins, err := m.TopologicalSort(m.pluginList)
if err != nil {
Lynx().Helper().Errorf("Exception in topological sorting plugins :", err)
Lynx().Helper().Errorf("Exception in topological sorting pluginList :", err)
panic(err)
}

Expand All @@ -140,11 +140,11 @@ func (m *DefaultLynxPluginManager) LoadPlugins(conf config.Config) {
}

func (m *DefaultLynxPluginManager) UnloadPlugins() {
size := len(m.plugins)
size := len(m.pluginList)
for i := 0; i < size; i++ {
err := m.plugins[i].Unload()
err := m.pluginList[i].Unload()
if err != nil {
Lynx().Helper().Errorf("Exception in uninstalling %v plugin", m.plugins[i].Name(), err)
Lynx().Helper().Errorf("Exception in uninstalling %v plugin", m.pluginList[i].Name(), err)
}
}
}
Expand All @@ -156,13 +156,13 @@ func (m *DefaultLynxPluginManager) LoadPluginsByName(name []string, conf config.

var pluginList []plugin.Plugin
for i := 0; i < len(name); i++ {
pluginList = append(pluginList, m.plugMap[name[i]])
pluginList = append(pluginList, m.pluginMap[name[i]])
}

// Sort plugins with the same level by weight.
// Sort pluginList with the same level by weight.
plugins, err := m.TopologicalSort(pluginList)
if err != nil {
Lynx().Helper().Errorf("Exception in topological sorting plugins :", err)
Lynx().Helper().Errorf("Exception in topological sorting pluginList :", err)
panic(err)
}

Expand All @@ -177,13 +177,13 @@ func (m *DefaultLynxPluginManager) LoadPluginsByName(name []string, conf config.

func (m *DefaultLynxPluginManager) UnloadPluginsByName(name []string) {
for i := 0; i < len(name); i++ {
err := m.plugMap[name[i]].Unload()
err := m.pluginMap[name[i]].Unload()
if err != nil {
Lynx().Helper().Errorf("Exception in uninstalling %v plugin", name[i], err)
}
}
}

func (m *DefaultLynxPluginManager) GetPlugin(name string) plugin.Plugin {
return m.plugMap[name]
return m.pluginMap[name]
}
4 changes: 2 additions & 2 deletions app/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func TestTopologicalSort(t *testing.T) {
pluginD := &MockPlugin{name: "D", depends: []string{"C", "A", "E"}, weight: 2}
pluginE := &MockPlugin{name: "E", depends: []string{}, weight: 3}

manager.(*DefaultLynxPluginManager).plugins = []plugin.Plugin{
manager.(*DefaultLynxPluginManager).pluginList = []plugin.Plugin{
pluginA,
pluginB,
pluginC,
pluginD,
pluginE,
}

result, err := manager.(*DefaultLynxPluginManager).TopologicalSort(manager.(*DefaultLynxPluginManager).plugins)
result, err := manager.(*DefaultLynxPluginManager).TopologicalSort(manager.(*DefaultLynxPluginManager).pluginList)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand Down

0 comments on commit 9f898c3

Please sign in to comment.