From 495ae1c5e3a831f5336b8b224e7f6554920b5b24 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 8 Feb 2018 22:53:01 +0100 Subject: [PATCH] implement remove user operation --- app/proxyman/command/command.go | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/app/proxyman/command/command.go b/app/proxyman/command/command.go index 4d93adcad..8646918c7 100644 --- a/app/proxyman/command/command.go +++ b/app/proxyman/command/command.go @@ -9,20 +9,32 @@ import ( "v2ray.com/core/proxy" ) +// InboundOperation is the interface for operations that applies to inbound handlers. type InboundOperation interface { + // ApplyInbound appliess this operation to the given inbound handler. ApplyInbound(context.Context, core.InboundHandler) error } +// OutboundOperation is the interface for operations that applies to outbound handlers. type OutboundOperation interface { + // ApplyOutbound applies this operation to the given outbound handler. ApplyOutbound(context.Context, core.OutboundHandler) error } -func (op *AddUserOperation) ApplyInbound(ctx context.Context, handler core.InboundHandler) error { - getInbound, ok := handler.(proxy.GetInbound) +func getInbound(handler core.InboundHandler) (proxy.Inbound, error) { + gi, ok := handler.(proxy.GetInbound) if !ok { - return newError("can't get inbound proxy from handler") + return nil, newError("can't get inbound proxy from handler.") + } + return gi.GetInbound(), nil +} + +// ApplyInbound implements InboundOperation. +func (op *AddUserOperation) ApplyInbound(ctx context.Context, handler core.InboundHandler) error { + p, err := getInbound(handler) + if err != nil { + return err } - p := getInbound.GetInbound() um, ok := p.(proxy.UserManager) if !ok { return newError("proxy is not an UserManager") @@ -30,17 +42,17 @@ func (op *AddUserOperation) ApplyInbound(ctx context.Context, handler core.Inbou return um.AddUser(ctx, op.User) } -func (op *AddUserOperation) ApplyOutbound(ctx context.Context, handler core.OutboundHandler) error { - getOutbound, ok := handler.(proxy.GetOutbound) - if !ok { - return newError("can't get outbound proxy from handler") +// ApplyInbound implements InboundOperation. +func (op *RemoveUserOperation) ApplyInbound(ctx context.Context, handler core.InboundHandler) error { + p, err := getInbound(handler) + if err != nil { + return err } - p := getOutbound.GetOutbound() um, ok := p.(proxy.UserManager) if !ok { - return newError("proxy in not an UserManager") + return newError("proxy is not an UserManager") } - return um.AddUser(ctx, op.User) + return um.RemoveUser(ctx, op.Email) } type handlerServer struct {