Exemplo n.º 1
0
// fillArgs fills arguments on the input structure using the args table of
// arguments.
func fillArgs(in reflect.Value, args [][]string) {
	if args == nil {
		return
	}

	for _, row := range args {
		path := row[0]
		var val interface{} = row[1]
		if reIsArray.MatchString(row[1]) {
			quotedStrs := reArrayElem.FindAllString(row[1], -1)
			strs := make([]*string, len(quotedStrs))
			for i, e := range quotedStrs {
				str := e[1 : len(e)-1]
				strs[i] = &str
			}
			val = strs
		} else if reIsNum.MatchString(row[1]) { // handle integer values
			num, err := strconv.ParseInt(row[1], 10, 64)
			if err == nil {
				val = num
			}
		}
		awsutil.SetValueAtAnyPath(in.Interface(), path, val)
	}
}
Exemplo n.º 2
0
// 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 tokens == nil {
		return nil
	}

	data := reflect.New(reflect.TypeOf(r.Data).Elem()).Interface()
	nr := NewRequest(r.Service, r.Operation, awsutil.CopyOf(r.Params), data)
	for i, intok := range nr.Operation.InputTokens {
		awsutil.SetValueAtAnyPath(nr.Params, intok, tokens[i])
	}
	return nr
}
Exemplo n.º 3
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.SetValueAtAnyPath(&s2, "b.b.c", "test0")
	assert.Equal(t, "test0", s2.B.B.C)
}