2023-06-07 13:18:56 -04:00
|
|
|
package hy
|
|
|
|
|
|
|
|
import (
|
2023-06-08 10:46:33 -04:00
|
|
|
"fmt"
|
|
|
|
"github.com/Yuzuki616/V2bX/conf"
|
2023-06-09 00:36:49 -04:00
|
|
|
vCore "github.com/Yuzuki616/V2bX/core"
|
2023-06-08 10:46:33 -04:00
|
|
|
"github.com/hashicorp/go-multierror"
|
|
|
|
"sync"
|
2023-06-07 13:18:56 -04:00
|
|
|
)
|
|
|
|
|
2023-06-09 00:36:49 -04:00
|
|
|
func init() {
|
|
|
|
vCore.RegisterCore("hy", NewHy)
|
|
|
|
}
|
|
|
|
|
2023-06-08 10:46:33 -04:00
|
|
|
type Hy struct {
|
|
|
|
servers sync.Map
|
2023-06-07 13:18:56 -04:00
|
|
|
}
|
|
|
|
|
2023-06-09 00:36:49 -04:00
|
|
|
func NewHy(_ *conf.CoreConfig) (vCore.Core, error) {
|
2023-06-08 10:46:33 -04:00
|
|
|
return &Hy{
|
|
|
|
servers: sync.Map{},
|
|
|
|
}, nil
|
2023-06-07 13:18:56 -04:00
|
|
|
}
|
|
|
|
|
2023-06-08 10:46:33 -04:00
|
|
|
func (h *Hy) Start() error {
|
|
|
|
return nil
|
2023-06-07 13:18:56 -04:00
|
|
|
}
|
|
|
|
|
2023-06-08 10:46:33 -04:00
|
|
|
func (h *Hy) Close() error {
|
|
|
|
var errs error
|
|
|
|
h.servers.Range(func(tag, s any) bool {
|
|
|
|
err := s.(*Server).Close()
|
|
|
|
if err != nil {
|
|
|
|
errs = multierror.Append(errs, fmt.Errorf("close %s error: %s", tag, err))
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
if errs != nil {
|
|
|
|
return errs
|
2023-06-07 13:18:56 -04:00
|
|
|
}
|
2023-06-08 10:46:33 -04:00
|
|
|
return nil
|
2023-06-07 13:18:56 -04:00
|
|
|
}
|