From cf61136da5cce02b65b559335fdf5f755c036d30 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 25 Feb 2020 13:31:20 +0300 Subject: [PATCH] small refactoring --- receive.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/receive.go b/receive.go index c31e89f..7607d00 100644 --- a/receive.go +++ b/receive.go @@ -16,25 +16,23 @@ import ( "github.com/nspcc-dev/neofs-api/service" "github.com/pkg/errors" "go.uber.org/zap" + "google.golang.org/grpc" ) func (r *router) receiveFile(c echo.Context) error { var ( + err error cid refs.CID oid refs.ObjectID obj *object.Object start = time.Now() + con *grpc.ClientConn ctx = c.Request().Context() - con, err = r.pool.getConnection(ctx) download = c.QueryParam("download") != "" ) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, err.Error()) - } - log := r.log.With( - zap.String("node", con.Target()), + // zap.String("node", con.Target()), zap.String("cid", c.Param("cid")), zap.String("oid", c.Param("oid"))) @@ -54,9 +52,20 @@ func (r *router) receiveFile(c echo.Context) error { ) } + { // try to connect or throw http error: + ctx, cancel := context.WithTimeout(ctx, r.timeout) + defer cancel() + + if con, err = r.pool.getConnection(ctx); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, err.Error()) + } + } + ctx, cancel := context.WithTimeout(ctx, r.timeout) defer cancel() + log = log.With(zap.String("node", con.Target())) + req := &object.GetRequest{Address: refs.Address{ObjectID: oid, CID: cid}} req.SetTTL(service.SingleForwardingTTL)