コード例 #1
0
ファイル: shared.go プロジェクト: bluet-deps/aws-sdk-go
// 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.SetValueAtPath(in.Interface(), path, val)
	}
}
コード例 #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 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
}
コード例 #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.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)
}