Newer
Older
GoModules / PluginSystem / plugins / pluginsHelper.go
root on 25 Jun 2022 648 bytes simple plugin system added
package plugins

//import "fmt"

type PluginInfo struct {
	Name     string
	About    string
	Commands Command
}

type Command struct {
	Name     string
	Callback func(args ...interface{})(string)
}

var Plugins []PluginInfo

func (p *PluginInfo) AddPluginInfo() {
	Plugins = append(Plugins, *p)
}

func (p *PluginInfo) Handle() {

}

func RunPlugin(cmd string, arg string)string{
	var result string
	for _, element := range Plugins {
		// fmt.Println("cmd:", key, "=>", "info:", element) // DEBUG
		if element.Commands.Name == cmd {
			result = element.Commands.Callback(arg)
			return result
		}
		result = "command not found"
	}
	return result
}