small refactoring

This commit is contained in:
Evgeniy Kulikov 2020-02-25 13:31:20 +03:00
parent 5512bd0b2f
commit cf61136da5
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2

View file

@ -16,25 +16,23 @@ import (
"github.com/nspcc-dev/neofs-api/service" "github.com/nspcc-dev/neofs-api/service"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc"
) )
func (r *router) receiveFile(c echo.Context) error { func (r *router) receiveFile(c echo.Context) error {
var ( var (
err error
cid refs.CID cid refs.CID
oid refs.ObjectID oid refs.ObjectID
obj *object.Object obj *object.Object
start = time.Now() start = time.Now()
con *grpc.ClientConn
ctx = c.Request().Context() ctx = c.Request().Context()
con, err = r.pool.getConnection(ctx)
download = c.QueryParam("download") != "" download = c.QueryParam("download") != ""
) )
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
log := r.log.With( log := r.log.With(
zap.String("node", con.Target()), // zap.String("node", con.Target()),
zap.String("cid", c.Param("cid")), zap.String("cid", c.Param("cid")),
zap.String("oid", c.Param("oid"))) 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) ctx, cancel := context.WithTimeout(ctx, r.timeout)
defer cancel() defer cancel()
log = log.With(zap.String("node", con.Target()))
req := &object.GetRequest{Address: refs.Address{ObjectID: oid, CID: cid}} req := &object.GetRequest{Address: refs.Address{ObjectID: oid, CID: cid}}
req.SetTTL(service.SingleForwardingTTL) req.SetTTL(service.SingleForwardingTTL)