mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-23 10:28:13 -05:00
31 lines
807 B
Go
31 lines
807 B
Go
|
package xray
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"github.com/xtls/xray-core/core"
|
||
|
"github.com/xtls/xray-core/features/outbound"
|
||
|
)
|
||
|
|
||
|
func (p *Xray) RemoveOutbound(tag string) error {
|
||
|
outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager)
|
||
|
err := outboundManager.RemoveHandler(context.Background(), tag)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (p *Xray) AddOutbound(config *core.OutboundHandlerConfig) error {
|
||
|
outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager)
|
||
|
rawHandler, err := core.CreateObject(p.Server, config)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
handler, ok := rawHandler.(outbound.Handler)
|
||
|
if !ok {
|
||
|
return fmt.Errorf("not an InboundHandler: %s", err)
|
||
|
}
|
||
|
if err := outboundManager.AddHandler(context.Background(), handler); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|