merge duplicated code

pull/1343/head
Darien Raymond 6 years ago
parent 275c92b6fa
commit c29f1c8cf0
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -70,15 +70,11 @@ type handlerServer struct {
}
func (s *handlerServer) AddInbound(ctx context.Context, request *AddInboundRequest) (*AddInboundResponse, error) {
rawHandler, err := core.CreateObject(s.s, request.Inbound)
if err != nil {
if err := core.AddInboundHandler(s.s, request.Inbound); err != nil {
return nil, err
}
handler, ok := rawHandler.(inbound.Handler)
if !ok {
return nil, newError("not an InboundHandler.")
}
return &AddInboundResponse{}, s.ihm.AddHandler(ctx, handler)
return &AddInboundResponse{}, nil
}
func (s *handlerServer) RemoveInbound(ctx context.Context, request *RemoveInboundRequest) (*RemoveInboundResponse, error) {
@ -104,15 +100,10 @@ func (s *handlerServer) AlterInbound(ctx context.Context, request *AlterInboundR
}
func (s *handlerServer) AddOutbound(ctx context.Context, request *AddOutboundRequest) (*AddOutboundResponse, error) {
rawHandler, err := core.CreateObject(s.s, request.Outbound)
if err != nil {
if err := core.AddOutboundHandler(s.s, request.Outbound); err != nil {
return nil, err
}
handler, ok := rawHandler.(outbound.Handler)
if !ok {
return nil, newError("not an OutboundHandler.")
}
return &AddOutboundResponse{}, s.ohm.AddHandler(ctx, handler)
return &AddOutboundResponse{}, nil
}
func (s *handlerServer) RemoveOutbound(ctx context.Context, request *RemoveOutboundRequest) (*RemoveOutboundResponse, error) {

@ -60,14 +60,9 @@ type Instance struct {
running bool
}
func addInboundHandlers(server *Instance, configs []*InboundHandlerConfig) error {
if len(configs) == 0 {
return nil
}
func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error {
inboundManager := server.GetFeature(inbound.ManagerType()).(inbound.Manager)
for _, inboundConfig := range configs {
rawHandler, err := CreateObject(server, inboundConfig)
rawHandler, err := CreateObject(server, config)
if err != nil {
return err
}
@ -78,19 +73,22 @@ func addInboundHandlers(server *Instance, configs []*InboundHandlerConfig) error
if err := inboundManager.AddHandler(context.Background(), handler); err != nil {
return err
}
return nil
}
return nil
func addInboundHandlers(server *Instance, configs []*InboundHandlerConfig) error {
for _, inboundConfig := range configs {
if err := AddInboundHandler(server, inboundConfig); err != nil {
return err
}
}
func addOutboundHandlers(server *Instance, configs []*OutboundHandlerConfig) error {
if len(configs) == 0 {
return nil
}
func AddOutboundHandler(server *Instance, config *OutboundHandlerConfig) error {
outboundManager := server.GetFeature(outbound.ManagerType()).(outbound.Manager)
for _, outboundConfig := range configs {
rawHandler, err := CreateObject(server, outboundConfig)
rawHandler, err := CreateObject(server, config)
if err != nil {
return err
}
@ -101,6 +99,14 @@ func addOutboundHandlers(server *Instance, configs []*OutboundHandlerConfig) err
if err := outboundManager.AddHandler(context.Background(), handler); err != nil {
return err
}
return nil
}
func addOutboundHandlers(server *Instance, configs []*OutboundHandlerConfig) error {
for _, outboundConfig := range configs {
if err := AddOutboundHandler(server, outboundConfig); err != nil {
return err
}
}
return nil

Loading…
Cancel
Save