V2bX/node/node.go

40 lines
771 B
Go
Raw Normal View History

package node
2022-06-01 13:35:41 -04:00
import (
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/core"
2022-10-09 23:31:15 -04:00
"github.com/Yuzuki616/V2bX/node/controller"
2022-06-01 13:35:41 -04:00
)
type Node struct {
2022-10-09 23:31:15 -04:00
controllers []*controller.Node
2022-06-01 13:35:41 -04:00
}
2022-10-09 23:31:15 -04:00
func New() *Node {
return &Node{}
2022-06-01 13:35:41 -04:00
}
2022-10-09 23:31:15 -04:00
func (n *Node) Start(nodes []*conf.NodeConfig, core *core.Core) error {
n.controllers = make([]*controller.Node, len(nodes))
for i, c := range nodes {
// Register controller service
n.controllers[i] = controller.New(core, panel.New(c.ApiConfig), c.ControllerConfig)
err := n.controllers[i].Start()
if err != nil {
return err
}
}
2022-06-01 13:35:41 -04:00
return nil
}
2022-10-09 23:31:15 -04:00
func (n *Node) Close() {
for _, c := range n.controllers {
err := c.Close()
if err != nil {
2022-10-09 23:31:15 -04:00
panic(err)
}
}
2022-10-09 23:31:15 -04:00
n.controllers = nil
2022-06-01 13:35:41 -04:00
}