added base code for plugin system
This commit is contained in:
0
plugin/deploy/.gitkeep
Normal file
0
plugin/deploy/.gitkeep
Normal file
54
plugin/plugin.go
Normal file
54
plugin/plugin.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Plugins Array of all plugins detected
|
||||
type Plugins struct {
|
||||
PluginsDetected []*Plugin
|
||||
}
|
||||
|
||||
// Plugin Information about the plugins available
|
||||
type Plugin struct {
|
||||
FolderName string
|
||||
PluginDescription string
|
||||
}
|
||||
|
||||
// DetectPlugins Detects all the plugins available
|
||||
func DetectPlugins()(*Plugins,error){
|
||||
config, err:= config.ConfigInit()
|
||||
if err != nil {
|
||||
return nil,err
|
||||
}
|
||||
folders, err := ioutil.ReadDir(config.PluginPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var plugins *Plugins = new(Plugins)
|
||||
|
||||
for _, f := range folders {
|
||||
if f.IsDir() {
|
||||
//Declare variable plugin of type Plugin
|
||||
var plugin Plugin
|
||||
|
||||
// Setting name of folder to plugin
|
||||
plugin.FolderName = f.Name()
|
||||
// Getting Description from file description.txt
|
||||
Description, err := ioutil.ReadFile(config.PluginPath + "/" + plugin.FolderName + "/description.txt")
|
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get Description from description.txt
|
||||
plugin.PluginDescription = string(Description)
|
||||
|
||||
plugins.PluginsDetected = append(plugins.PluginsDetected, &plugin)
|
||||
}
|
||||
}
|
||||
|
||||
return plugins,nil
|
||||
}
|
||||
Reference in New Issue
Block a user