// NextPage returns a new Request that can be executed to return the next
// page of result data. Call .Send() on this request to execute it.
func (r *Request) NextPage() *Request {
	tokens := r.nextPageTokens()
	if len(tokens) == 0 {
		return nil
	}

	data := reflect.New(reflect.TypeOf(r.Data).Elem()).Interface()
	nr := New(r.Config, r.ClientInfo, r.Handlers, r.Retryer, r.Operation, awsutil.CopyOf(r.Params), data)
	for i, intok := range nr.Operation.InputTokens {
		awsutil.SetValueAtPath(nr.Params, intok, tokens[i])
	}
	return nr
}
Example #2
0
func TestSetValueAtPathSuccess(t *testing.T) {
	var s Struct
	awsutil.SetValueAtPath(&s, "C", "test1")
	awsutil.SetValueAtPath(&s, "B.B.C", "test2")
	awsutil.SetValueAtPath(&s, "B.D.C", "test3")
	assert.Equal(t, "test1", s.C)
	assert.Equal(t, "test2", s.B.B.C)
	assert.Equal(t, "test3", s.B.D.C)

	awsutil.SetValueAtPath(&s, "B.*.C", "test0")
	assert.Equal(t, "test0", s.B.B.C)
	assert.Equal(t, "test0", s.B.D.C)

	var s2 Struct
	awsutil.SetValueAtPath(&s2, "b.b.c", "test0")
	assert.Equal(t, "test0", s2.B.B.C)
	awsutil.SetValueAtPath(&s2, "A", []Struct{{}})
	assert.Equal(t, []Struct{{}}, s2.A)

	str := "foo"

	s3 := Struct{}
	awsutil.SetValueAtPath(&s3, "b.b.c", str)
	assert.Equal(t, "foo", s3.B.B.C)

	s3 = Struct{B: &Struct{B: &Struct{C: str}}}
	awsutil.SetValueAtPath(&s3, "b.b.c", nil)
	assert.Equal(t, "", s3.B.B.C)

	s3 = Struct{}
	awsutil.SetValueAtPath(&s3, "b.b.c", nil)
	assert.Equal(t, "", s3.B.B.C)

	s3 = Struct{}
	awsutil.SetValueAtPath(&s3, "b.b.c", &str)
	assert.Equal(t, "foo", s3.B.B.C)

	var s4 struct{ Name *string }
	awsutil.SetValueAtPath(&s4, "Name", str)
	assert.Equal(t, str, *s4.Name)

	s4 = struct{ Name *string }{}
	awsutil.SetValueAtPath(&s4, "Name", nil)
	assert.Equal(t, (*string)(nil), s4.Name)

	s4 = struct{ Name *string }{Name: &str}
	awsutil.SetValueAtPath(&s4, "Name", nil)
	assert.Equal(t, (*string)(nil), s4.Name)

	s4 = struct{ Name *string }{}
	awsutil.SetValueAtPath(&s4, "Name", &str)
	assert.Equal(t, str, *s4.Name)
}