Compare commits

..

No commits in common. "edc9c7aecb798a23b78ccd3499fa2e97fe955ac5" and "f8bafbbff091f42bc069322db28b9d3562e7e857" have entirely different histories.

2 changed files with 7 additions and 47 deletions

View file

@ -2,7 +2,6 @@ package main
import (
"fmt"
"log"
"time"
)
@ -11,34 +10,17 @@ type Resources interface {
AgentInfo() map[string]interface{}
}
// FILLME creating new plugin interface template
// type NewPluginInterface interface {
// PluginMethod() returnType
// }
// Loads Plugins and runs them concurrently.
// Loads Plugins and runs them.
// When you create a new plugin create a new interface and call this plugin in this function
func PluginManager() {
chanPlug := make(chan interface{})
go LoadPlugin("resources", chanPlug)
res, ok := <-chanPlug
var resources Resources = res.(Resources)
checkPlugin(res, ok)
// FILLME Loading new plugin template
// go LoadPlugin("pluginName", chanPlug)
// res, ok = <-chanPlug
// var pluginName NewPluginInterface = res.(NewPluginInterface)
// checkPlugin(res, ok)
// Run plugins concurrently and log out
var resources Resources = LoadPlugin("resources").(Resources)
// var pluginName NewPluginInterface = LoadPlugin("pluginName").(NewPluginInterface)
for {
go logPlugin("AgentInfo", resources.AgentInfo())
// FILLME Running/Logout a plugin template
// go logPlugin("InfoAboutFunction", pluginName.Function() )
logPlugin("AgentInfo", resources.AgentInfo())
time.Sleep(30 * time.Second)
}
}
@ -51,23 +33,6 @@ func logPlugin(title string, mp map[string]interface{}) {
}
}
// Checks plugin status
func checkPlugin(plugVal interface{}, status bool) {
if status {
if plugVal == nil {
log.Fatal("Plugin loaded but there is no value!")
} else {
log.Println("Plugin loaded and ready to use")
}
} else {
if plugVal == nil {
log.Fatal("Plugin closed and there is no value! ")
} else {
log.Fatal("Plugin closed or there is an error")
}
}
}
// // TODO response to Lider
// // func createResponse() {

View file

@ -8,11 +8,11 @@ import (
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
)
// Load Plugin placed in PluginDir, returns empty interface with channel
// Load Plugin placed in PluginDir, returns empty interface.
// Do not forget to cast in plugin manager
//
// Give Plugin Name as argument and be sure you compiled plugins with `-buildmode=plugin` to PluginDir as `pluginname.so`
func LoadPlugin(plugName string, chn chan interface{}) {
func LoadPlugin(plugName string) interface{} {
// TODO if error caugth try without relative path, this will be good for local testing
plug, err := plugin.Open(PluginDir + plugName + ".so")
@ -28,10 +28,5 @@ func LoadPlugin(plugName string, chn chan interface{}) {
fmt.Println("unexpected type from module symbol")
os.Exit(1)
}
chn <- plugOut
return plugOut
}
// NEXT implement unload function
// func UnloadPlugin(plugName string) interface{} {
// }