func (r *Runner) next(instrs []instruction, hsURL string, i int) (*http.Request, *instruction, int) {
	if i >= len(instrs) {
		return nil, nil, 0
	}
	instr := instrs[i]
	i++

	var body io.Reader
	if instr.body == nil && instr.bodyFn != nil {
		instr.body = instr.bodyFn(r.lookup)
	}
	if instr.body != nil {
		b, err := json.Marshal(instr.body)
		if err != nil {
			r.log("Stopping. Failed to marshal JSON request for instruction: %s -- %+v", err, instr)
			return nil, nil, 0
		}
		body = bytes.NewBuffer(b)
	}
	req, err := http.NewRequest(instr.method, instr.url(hsURL, r.lookup), body)
	if err != nil {
		r.log("Stopping. Failed to form NewRequest for instruction: %s -- %+v \n", err, instr)
		return nil, nil, 0
	}

	q := req.URL.Query()
	if instr.accessToken != "" {
		at, ok := r.lookup.Load(instr.accessToken)
		if ok {
			q.Set("access_token", at.(string))
		}
	}
	for paramName, paramValue := range instr.queryParams {
		// if the variable starts with a '.' then use the lookup table, else use the string literally
		// this handles scenarios like:
		// { $roomId: ".room_0", $eventType: "m.room.message" }
		var valToEncode string
		if paramValue[0] == '.' {
			vint, ok := r.lookup.Load(strings.TrimPrefix(paramValue, "."))
			if ok {
				valToEncode = vint.(string)
			}
		} else {
			valToEncode = paramValue
		}
		q.Set(paramName, valToEncode)
	}
	req.URL.RawQuery = q.Encode()
	return req, &instr, i
}
// next returns the next request to make, along with its instruction. Return nil if there are no more instructions.
next returns the next request to make, along with its instruction. Return nil if there are no more instructions.
// next returns the next request to make along with its instruction . Return nil if there are no more instructions .
func (r *Runner) next(instrs []instruction, hsURL string, i int) (*http.Request, *instruction, int) {
	if i >= len(instrs) {
		return nil, nil, 0
	}
	instr := instrs[i]
	i++
	var body io.Reader
	if instr.body == nil && instr.bodyFn != nil {
		instr.body = instr.bodyFn(r.lookup)
	}
	if instr.body != nil {
		b, err := json.Marshal(instr.body)
		if err != nil {
			r.log("Stopping. Failed to marshal JSON request for instruction: %s -- %+v", err, instr)
			return nil, nil, 0
		}
		body = bytes.NewBuffer(b)
	}
	req, err := http.NewRequest(instr.method, instr.url(hsURL, r.lookup), body)
	if err != nil {
		r.log("Stopping. Failed to form NewRequest for instruction: %s -- %+v \n", err, instr)
		return nil, nil, 0
	}
	q := req.URL.Query()
	if instr.accessToken != "" {
		at, ok := r.lookup.Load(instr.accessToken)
		if ok {
			q.Set("access_token", at.(string))
		}
	}
	for paramName, paramValue := range instr.queryParams {
		var valToEncode string
		if paramValue[0] == '.' {
			vint, ok := r.lookup.Load(strings.TrimPrefix(paramValue, "."))
			if ok {
				valToEncode = vint.(string)
			}
		} else {
			valToEncode = paramValue
		}
		q.Set(paramName, valToEncode)
	}
	req.URL.RawQuery = q.Encode()
	return req, &instr, i
}
func ( r * Runner ) next ( instrs [ ] instruction , hsURL string , i int ) ( * http . Request , * instruction , int ) { if i >= len ( instrs ) { return nil , nil , 0 } instr := instrs [ i ] i ++ var body io . Reader if instr . body == nil && instr . bodyFn != nil { instr . body = instr . bodyFn ( r . lookup ) } if instr . body != nil { b , err := json . Marshal ( instr . body ) if err != nil { r . log ( " " , err , instr ) return nil , nil , 0 } body = bytes . NewBuffer ( b ) } req , err := http . NewRequest ( instr . method , instr . url ( hsURL , r . lookup ) , body ) if err != nil { r . log ( " \n " , err , instr ) return nil , nil , 0 } q := req . URL . Query ( ) if instr . accessToken != " " { at , ok := r . lookup . Load ( instr . accessToken ) if ok { q . Set ( " " , at . ( string ) ) } } for paramName , paramValue := range instr . queryParams { var valToEncode string if paramValue [ 0 ] == '.' { vint , ok := r . lookup . Load ( strings . TrimPrefix ( paramValue , " " ) ) if ok { valToEncode = vint . ( string ) } } else { valToEncode = paramValue } q . Set ( paramName , valToEncode ) } req . URL . RawQuery = q . Encode ( ) return req , & instr , i }
next returns the next request to make, along with its instruction.
next returns the next request to make along with its instruction .
// if the variable starts with a '.' then use the lookup table, else use the string literally // this handles scenarios like: // { $roomId: ".room_0", $eventType: "m.room.message" }