go-zero/zrpc/internal/mock/depositserver.go

23 lines
543 B
Go
Raw Normal View History

2020-08-26 14:19:16 +08:00
package mock
import (
"context"
"time"
2020-08-26 14:19:16 +08:00
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
2021-03-28 21:20:04 +08:00
// DepositServer is used for mocking.
2021-04-15 19:49:17 +08:00
type DepositServer struct{}
2020-08-26 14:19:16 +08:00
2021-03-28 20:42:11 +08:00
// Deposit handles the deposit requests.
2020-08-26 14:19:16 +08:00
func (*DepositServer) Deposit(ctx context.Context, req *DepositRequest) (*DepositResponse, error) {
if req.GetAmount() < 0 {
return nil, status.Errorf(codes.InvalidArgument, "cannot deposit %v", req.GetAmount())
}
time.Sleep(time.Duration(req.GetAmount()) * time.Millisecond)
2020-08-26 14:19:16 +08:00
return &DepositResponse{Ok: true}, nil
}