mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 18:08:14 -05:00
48 lines
914 B
Go
48 lines
914 B
Go
package node
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/Yuzuki616/V2bX/api/panel"
|
|
"github.com/Yuzuki616/V2bX/conf"
|
|
vCore "github.com/Yuzuki616/V2bX/core"
|
|
)
|
|
|
|
type Node struct {
|
|
controllers []*Controller
|
|
}
|
|
|
|
func New() *Node {
|
|
return &Node{}
|
|
}
|
|
|
|
func (n *Node) Start(nodes []*conf.NodeConfig, core vCore.Core) error {
|
|
n.controllers = make([]*Controller, len(nodes))
|
|
for i, c := range nodes {
|
|
p, err := panel.New(c.ApiConfig)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// Register controller service
|
|
n.controllers[i] = NewController(core, p, c.ControllerConfig)
|
|
err = n.controllers[i].Start()
|
|
if err != nil {
|
|
return fmt.Errorf("start node controller [%s-%s-%d] error: %s",
|
|
c.ApiConfig.NodeType,
|
|
c.ApiConfig.APIHost,
|
|
c.ApiConfig.NodeID,
|
|
err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (n *Node) Close() {
|
|
for _, c := range n.controllers {
|
|
err := c.Close()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
n.controllers = nil
|
|
}
|