mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-06-29 18:45:23 +00:00
implement remove user operation
This commit is contained in:
parent
f8ce1945e1
commit
495ae1c5e3
|
@ -9,20 +9,32 @@ import (
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InboundOperation is the interface for operations that applies to inbound handlers.
|
||||||
type InboundOperation interface {
|
type InboundOperation interface {
|
||||||
|
// ApplyInbound appliess this operation to the given inbound handler.
|
||||||
ApplyInbound(context.Context, core.InboundHandler) error
|
ApplyInbound(context.Context, core.InboundHandler) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OutboundOperation is the interface for operations that applies to outbound handlers.
|
||||||
type OutboundOperation interface {
|
type OutboundOperation interface {
|
||||||
|
// ApplyOutbound applies this operation to the given outbound handler.
|
||||||
ApplyOutbound(context.Context, core.OutboundHandler) error
|
ApplyOutbound(context.Context, core.OutboundHandler) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *AddUserOperation) ApplyInbound(ctx context.Context, handler core.InboundHandler) error {
|
func getInbound(handler core.InboundHandler) (proxy.Inbound, error) {
|
||||||
getInbound, ok := handler.(proxy.GetInbound)
|
gi, ok := handler.(proxy.GetInbound)
|
||||||
if !ok {
|
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)
|
um, ok := p.(proxy.UserManager)
|
||||||
if !ok {
|
if !ok {
|
||||||
return newError("proxy is not an UserManager")
|
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)
|
return um.AddUser(ctx, op.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *AddUserOperation) ApplyOutbound(ctx context.Context, handler core.OutboundHandler) error {
|
// ApplyInbound implements InboundOperation.
|
||||||
getOutbound, ok := handler.(proxy.GetOutbound)
|
func (op *RemoveUserOperation) ApplyInbound(ctx context.Context, handler core.InboundHandler) error {
|
||||||
if !ok {
|
p, err := getInbound(handler)
|
||||||
return newError("can't get outbound proxy from handler")
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
p := getOutbound.GetOutbound()
|
|
||||||
um, ok := p.(proxy.UserManager)
|
um, ok := p.(proxy.UserManager)
|
||||||
if !ok {
|
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 {
|
type handlerServer struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user