Newer
Older
"strings"
"sync"
"github.com/iotaledger/goshimmer/packages/daemon"
wg *sync.WaitGroup
loggers []*Logger
loadedPlugins []*Plugin
logLevel int
var disabledPlugins = make(map[string]bool)
for _, disabledPlugin := range strings.Fields(*DISABLE_PLUGINS.Value) {
disabledPlugins[strings.ToLower(disabledPlugin)] = true
}
node := &Node{
logLevel: *LOG_LEVEL.Value,
loggers: make([]*Logger, 0),
wg: &sync.WaitGroup{},
loadedPlugins: make([]*Plugin, 0),
}
node.AddLogger(DEFAULT_LOGGER)
node.Load(plugins...)
return node
}
func Run(plugins ...*Plugin) *Node {
}
func (node *Node) AddLogger(logger *Logger) {
}
func (node *Node) LogSuccess(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_SUCCESS {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogSuccess(pluginName, message)
}
}
}
}
func (node *Node) LogInfo(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_INFO {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogInfo(pluginName, message)
}
}
}
func (node *Node) LogDebug(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_DEBUG {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogDebug(pluginName, message)
}
}
}
func (node *Node) LogWarning(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_WARNING {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogWarning(pluginName, message)
}
}
}
}
func (node *Node) LogFailure(pluginName string, message string) {
if node.logLevel >= LOG_LEVEL_FAILURE {
for _, logger := range node.loggers {
if logger.Enabled {
logger.LogFailure(pluginName, message)
}
}
}
}
func (node *Node) Load(plugins ...*Plugin) {
if len(plugins) >= 1 {
for _, plugin := range plugins {
if _, exists := disabledPlugins[strings.ToLower(strings.Replace(plugin.Name, " ", "", -1))]; !exists {
plugin.wg = node.wg
plugin.Node = node
node.LogInfo("Node", "Loading Plugin: "+plugin.Name+" ... done")
node.loadedPlugins = append(node.loadedPlugins, plugin)
}
}
}
//node.loadedPlugins = append(node.loadedPlugins, plugins...)
if len(node.loadedPlugins) >= 1 {
for _, plugin := range node.loadedPlugins {
plugin.Events.Run.Trigger(plugin)
node.LogSuccess("Node", "Starting Plugin: "+plugin.Name+" ... done")
}
}
node.LogSuccess("Node", "Starting background workers ...")