Package: awsutil

import "../ibm-cos-sdk-go/aws/awsutil"

Function Summary collapse

Function Details

func Copy(dst, src interface{})

Copy deeply copies a src structure to dst. Useful for copying request and response structures.

Can copy between structs of different type, but will only copy fields which are assignable, and exist in both structs. Fields which are not assignable, or do not exist in both structs are ignored.

Examples:

type Foo struct { A int B []*string } // Create the initial value str1 := "hello" str2 := "bye bye" f1 := &Foo{A: 1, B: []*string{&str1, &str2}} // Do the copy var f2 Foo awsutil.Copy(&f2, f1) // Print the result fmt.Println(awsutil.Prettify(f2))


14
15
16
17
18
19
20
21
// File 'aws/awsutil/copy.go', line 14

func Copy(dst, src interface{}) { dstval := reflect.ValueOf(dst) if !dstval.IsValid() { panic("Copy dst cannot be nil") } rcopy(dstval, reflect.ValueOf(src), true) }

func CopyOf(src interface{}) (dst interface{})

CopyOf returns a copy of src while also allocating the memory for dst. src must be a pointer type or this operation will fail.

Examples:

type Foo struct { A int B []*string } // Create the initial value str1 := "hello" str2 := "bye bye" f1 := &Foo{A: 1, B: []*string{&str1, &str2}} // Do the copy v := awsutil.CopyOf(f1) var f2 *Foo = v.(*Foo) // Print the result fmt.Println(awsutil.Prettify(f2))


25
26
27
28
29
30
// File 'aws/awsutil/copy.go', line 25

func CopyOf(src interface{}) (dst interface{}) { dsti := reflect.New(reflect.TypeOf(src).Elem()) dst = dsti.Interface() rcopy(dsti, reflect.ValueOf(src), true) return }

func DeepEqual(a, b interface{}) bool

DeepEqual returns if the two values are deeply equal like reflect.DeepEqual. In addition to this, this method will also dereference the input values if possible so the DeepEqual performed will not fail if one parameter is a pointer and the other is not.

DeepEqual will not perform indirection of nested values of the input parameters.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// File 'aws/awsutil/equal.go', line 12

func DeepEqual(a, b interface{}) bool { ra := reflect.Indirect(reflect.ValueOf(a)) rb := reflect.Indirect(reflect.ValueOf(b)) if raValid, rbValid := ra.IsValid(), rb.IsValid(); !raValid && !rbValid { // If the elements are both nil, and of the same type they are equal // If they are of different types they are not equal return reflect.TypeOf(a) == reflect.TypeOf(b) } else if raValid != rbValid { // Both values must be valid to be equal return false } return reflect.DeepEqual(ra.Interface(), rb.Interface()) }

func Prettify(i interface{}) string

Prettify returns the string representation of a value.



11
12
13
14
15
// File 'aws/awsutil/prettify.go', line 11

func Prettify(i interface{}) string { var buf bytes.Buffer prettify(reflect.ValueOf(i), 0, &buf) return buf.String() }

func SetValueAtPath(i interface{}, path string, v interface{})

SetValueAtPath sets a value at the case insensitive lexical path inside of a structure.



186
187
188
189
190
191
192
193
194
// File 'aws/awsutil/path_value.go', line 186

func SetValueAtPath(i interface{}, path string, v interface{}) { rvals := rValuesAtPath(i, path, true, false, v == nil) for _, rval := range rvals { if rval.Kind() == reflect.Ptr && rval.IsNil() { continue } setValue(rval, v) } }

func StringValue(i interface{}) string

StringValue returns the string representation of a value.

Deprecated: Use Prettify instead.



12
13
14
15
16
// File 'aws/awsutil/string_value.go', line 12

func StringValue(i interface{}) string { var buf bytes.Buffer stringValue(reflect.ValueOf(i), 0, &buf) return buf.String() }

func ValuesAtPath(i interface{}, path string) ([]interface{}, error)

ValuesAtPath returns a list of values at the case insensitive lexical path inside of a structure.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// File 'aws/awsutil/path_value.go', line 157

func ValuesAtPath(i interface{}, path string) ([]interface{}, error) { result, err := jmespath.Search(path, i) if err != nil { return nil, err } v := reflect.ValueOf(result) if !v.IsValid() || (v.Kind() == reflect.Ptr && v.IsNil()) { return nil, nil } if s, ok := result.([]interface{}); ok { return s, err } if v.Kind() == reflect.Map && v.Len() == 0 { return nil, nil } if v.Kind() == reflect.Slice { out := make([]interface{}, v.Len()) for i := 0; i < v.Len(); i++ { out[i] = v.Index(i).Interface() } return out, nil } return []interface{}{result}, nil }