2022-08-12 06:02:06 -04:00
|
|
|
package core
|
2022-07-28 11:00:05 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/xtls/xray-core/core"
|
|
|
|
"github.com/xtls/xray-core/features/outbound"
|
|
|
|
)
|
|
|
|
|
2022-08-12 06:02:06 -04:00
|
|
|
func (p *Core) RemoveOutbound(tag string) error {
|
2022-08-12 06:44:56 -04:00
|
|
|
err := p.ohm.RemoveHandler(context.Background(), tag)
|
2022-07-28 11:00:05 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-08-12 06:02:06 -04:00
|
|
|
func (p *Core) AddOutbound(config *core.OutboundHandlerConfig) error {
|
2022-07-28 11:00:05 -04:00
|
|
|
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)
|
|
|
|
}
|
2022-08-12 06:44:56 -04:00
|
|
|
if err := p.ohm.AddHandler(context.Background(), handler); err != nil {
|
2022-07-28 11:00:05 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|