// AddScopedReq adds a server-scoped request (from the server request `from`) to our multi-client // with the `uid` that uniquely identifies the request within the group (for getting response from `Outcome`) func (c *defClient) AddScopedReq(sr *ScopedReq) MultiClient { c.Lock() defer c.Unlock() if _, exists := c.requests[sr.Uid]; exists { panic(fmt.Sprintf("Cannot add scoped request with UID '%v' - already exists within this MultiClient", sr.Uid)) } from := sr.From if from == nil { from = c.defaultFromScope } var clientReq *client.Request var err error // if no from, just use normal client request if from == nil { clientReq, err = client.NewRequest(sr.Service, sr.Endpoint, sr.Req) } else { clientReq, err = from.ScopedRequest(sr.Service, sr.Endpoint, sr.Req) } c.requests[sr.Uid] = clientReq c.responses[sr.Uid] = sr.Rsp if err != nil { c.errors.set(sr.Uid, clientReq, errors.InternalServerError("com.hailocab.kernel.multirequest.badrequest", err.Error()), from) } else { clientReq.SetOptions(sr.Options) } return c }