Skip to content

Commit d993b41

Browse files
committed
Switch from *map to just map [Breaking Change]
This change will impact all usage of maps within the SDK operations. The best way to migrate to this new changes is just not to pass the pointer of a map to an operation, or dereference maps when extracting information from operation outputs. Fixes #252 Addresses #114
1 parent 5df7b34 commit d993b41

File tree

56 files changed

+327
-753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+327
-753
lines changed

aws/awsutil/string_value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func stringValue(v reflect.Value, indent int, buf *bytes.Buffer) {
4242
if name[0:1] == strings.ToLower(name[0:1]) {
4343
continue // ignore unexported fields
4444
}
45-
if (f.Kind() == reflect.Ptr || f.Kind() == reflect.Slice) && f.IsNil() {
45+
if (f.Kind() == reflect.Ptr || f.Kind() == reflect.Slice || f.Kind() == reflect.Map) && f.IsNil() {
4646
continue // ignore unset fields
4747
}
4848
names = append(names, name)

aws/param_validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (v *validator) validateStruct(value reflect.Value, path string) {
6767
notset := false
6868
if f.Tag.Get("required") != "" {
6969
switch fvalue.Kind() {
70-
case reflect.Ptr, reflect.Slice:
70+
case reflect.Ptr, reflect.Slice, reflect.Map:
7171
if fvalue.IsNil() {
7272
notset = true
7373
}

aws/param_validator_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var service = func() *aws.Service {
1818
}()
1919

2020
type StructShape struct {
21-
RequiredList []*ConditionalStructShape `required:"true"`
22-
RequiredMap *map[string]*ConditionalStructShape `required:"true"`
23-
RequiredBool *bool `required:"true"`
21+
RequiredList []*ConditionalStructShape `required:"true"`
22+
RequiredMap map[string]*ConditionalStructShape `required:"true"`
23+
RequiredBool *bool `required:"true"`
2424
OptionalStruct *ConditionalStructShape
2525

2626
hiddenParameter *string
@@ -40,7 +40,7 @@ type ConditionalStructShape struct {
4040
func TestNoErrors(t *testing.T) {
4141
input := &StructShape{
4242
RequiredList: []*ConditionalStructShape{},
43-
RequiredMap: &map[string]*ConditionalStructShape{
43+
RequiredMap: map[string]*ConditionalStructShape{
4444
"key1": &ConditionalStructShape{Name: aws.String("Name")},
4545
"key2": &ConditionalStructShape{Name: aws.String("Name")},
4646
},
@@ -66,7 +66,7 @@ func TestMissingRequiredParameters(t *testing.T) {
6666
func TestNestedMissingRequiredParameters(t *testing.T) {
6767
input := &StructShape{
6868
RequiredList: []*ConditionalStructShape{&ConditionalStructShape{}},
69-
RequiredMap: &map[string]*ConditionalStructShape{
69+
RequiredMap: map[string]*ConditionalStructShape{
7070
"key1": &ConditionalStructShape{Name: aws.String("Name")},
7171
"key2": &ConditionalStructShape{},
7272
},

internal/fixtures/helpers/param_filler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (f paramFiller) paramsStructStruct(value map[string]interface{}, shape *api
102102

103103
// paramsStructMap returns the string representation of a map of values
104104
func (f paramFiller) paramsStructMap(value map[string]interface{}, shape *api.Shape) string {
105-
out := "&" + f.typeName(shape)[1:] + "{\n"
105+
out := f.typeName(shape) + "{\n"
106106
keys := utilsort.SortedKeys(value)
107107
for _, k := range keys {
108108
v := value[k]

internal/model/api/operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (e *example) traverseStruct(s *Shape, required, payload bool) string {
251251
func (e *example) traverseMap(s *Shape, required, payload bool) string {
252252
var buf bytes.Buffer
253253
t := reType.ReplaceAllString(s.GoTypeElem(), s.API.PackageName()+".$1")
254-
buf.WriteString("&" + t + "{")
254+
buf.WriteString(t + "{")
255255
if required {
256256
buf.WriteString(" // Required")
257257
}

internal/model/api/shape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func goType(s *Shape, withPkgName bool) string {
116116
}
117117
return "*" + s.ShapeName
118118
case "map":
119-
return "*map[string]" + s.ValueRef.GoType()
119+
return "map[string]" + s.ValueRef.GoType()
120120
case "list":
121121
return "[]" + s.MemberRef.GoType()
122122
case "boolean":

internal/protocol/ec2query/build_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ type InputService1ProtocolTest struct {
3737

3838
// New returns a new InputService1ProtocolTest client.
3939
func NewInputService1ProtocolTest(config *aws.Config) *InputService1ProtocolTest {
40-
if config == nil {
41-
config = &aws.Config{}
42-
}
43-
4440
service := &aws.Service{
4541
Config: aws.DefaultConfig.Merge(config),
4642
ServiceName: "inputservice1protocoltest",
@@ -120,10 +116,6 @@ type InputService2ProtocolTest struct {
120116

121117
// New returns a new InputService2ProtocolTest client.
122118
func NewInputService2ProtocolTest(config *aws.Config) *InputService2ProtocolTest {
123-
if config == nil {
124-
config = &aws.Config{}
125-
}
126-
127119
service := &aws.Service{
128120
Config: aws.DefaultConfig.Merge(config),
129121
ServiceName: "inputservice2protocoltest",
@@ -205,10 +197,6 @@ type InputService3ProtocolTest struct {
205197

206198
// New returns a new InputService3ProtocolTest client.
207199
func NewInputService3ProtocolTest(config *aws.Config) *InputService3ProtocolTest {
208-
if config == nil {
209-
config = &aws.Config{}
210-
}
211-
212200
service := &aws.Service{
213201
Config: aws.DefaultConfig.Merge(config),
214202
ServiceName: "inputservice3protocoltest",
@@ -296,10 +284,6 @@ type InputService4ProtocolTest struct {
296284

297285
// New returns a new InputService4ProtocolTest client.
298286
func NewInputService4ProtocolTest(config *aws.Config) *InputService4ProtocolTest {
299-
if config == nil {
300-
config = &aws.Config{}
301-
}
302-
303287
service := &aws.Service{
304288
Config: aws.DefaultConfig.Merge(config),
305289
ServiceName: "inputservice4protocoltest",
@@ -377,10 +361,6 @@ type InputService5ProtocolTest struct {
377361

378362
// New returns a new InputService5ProtocolTest client.
379363
func NewInputService5ProtocolTest(config *aws.Config) *InputService5ProtocolTest {
380-
if config == nil {
381-
config = &aws.Config{}
382-
}
383-
384364
service := &aws.Service{
385365
Config: aws.DefaultConfig.Merge(config),
386366
ServiceName: "inputservice5protocoltest",
@@ -458,10 +438,6 @@ type InputService6ProtocolTest struct {
458438

459439
// New returns a new InputService6ProtocolTest client.
460440
func NewInputService6ProtocolTest(config *aws.Config) *InputService6ProtocolTest {
461-
if config == nil {
462-
config = &aws.Config{}
463-
}
464-
465441
service := &aws.Service{
466442
Config: aws.DefaultConfig.Merge(config),
467443
ServiceName: "inputservice6protocoltest",
@@ -539,10 +515,6 @@ type InputService7ProtocolTest struct {
539515

540516
// New returns a new InputService7ProtocolTest client.
541517
func NewInputService7ProtocolTest(config *aws.Config) *InputService7ProtocolTest {
542-
if config == nil {
543-
config = &aws.Config{}
544-
}
545-
546518
service := &aws.Service{
547519
Config: aws.DefaultConfig.Merge(config),
548520
ServiceName: "inputservice7protocoltest",
@@ -620,10 +592,6 @@ type InputService8ProtocolTest struct {
620592

621593
// New returns a new InputService8ProtocolTest client.
622594
func NewInputService8ProtocolTest(config *aws.Config) *InputService8ProtocolTest {
623-
if config == nil {
624-
config = &aws.Config{}
625-
}
626-
627595
service := &aws.Service{
628596
Config: aws.DefaultConfig.Merge(config),
629597
ServiceName: "inputservice8protocoltest",

internal/protocol/ec2query/unmarshal_test.go

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ type OutputService1ProtocolTest struct {
3737

3838
// New returns a new OutputService1ProtocolTest client.
3939
func NewOutputService1ProtocolTest(config *aws.Config) *OutputService1ProtocolTest {
40-
if config == nil {
41-
config = &aws.Config{}
42-
}
43-
4440
service := &aws.Service{
4541
Config: aws.DefaultConfig.Merge(config),
4642
ServiceName: "outputservice1protocoltest",
@@ -132,10 +128,6 @@ type OutputService2ProtocolTest struct {
132128

133129
// New returns a new OutputService2ProtocolTest client.
134130
func NewOutputService2ProtocolTest(config *aws.Config) *OutputService2ProtocolTest {
135-
if config == nil {
136-
config = &aws.Config{}
137-
}
138-
139131
service := &aws.Service{
140132
Config: aws.DefaultConfig.Merge(config),
141133
ServiceName: "outputservice2protocoltest",
@@ -213,10 +205,6 @@ type OutputService3ProtocolTest struct {
213205

214206
// New returns a new OutputService3ProtocolTest client.
215207
func NewOutputService3ProtocolTest(config *aws.Config) *OutputService3ProtocolTest {
216-
if config == nil {
217-
config = &aws.Config{}
218-
}
219-
220208
service := &aws.Service{
221209
Config: aws.DefaultConfig.Merge(config),
222210
ServiceName: "outputservice3protocoltest",
@@ -294,10 +282,6 @@ type OutputService4ProtocolTest struct {
294282

295283
// New returns a new OutputService4ProtocolTest client.
296284
func NewOutputService4ProtocolTest(config *aws.Config) *OutputService4ProtocolTest {
297-
if config == nil {
298-
config = &aws.Config{}
299-
}
300-
301285
service := &aws.Service{
302286
Config: aws.DefaultConfig.Merge(config),
303287
ServiceName: "outputservice4protocoltest",
@@ -375,10 +359,6 @@ type OutputService5ProtocolTest struct {
375359

376360
// New returns a new OutputService5ProtocolTest client.
377361
func NewOutputService5ProtocolTest(config *aws.Config) *OutputService5ProtocolTest {
378-
if config == nil {
379-
config = &aws.Config{}
380-
}
381-
382362
service := &aws.Service{
383363
Config: aws.DefaultConfig.Merge(config),
384364
ServiceName: "outputservice5protocoltest",
@@ -456,10 +436,6 @@ type OutputService6ProtocolTest struct {
456436

457437
// New returns a new OutputService6ProtocolTest client.
458438
func NewOutputService6ProtocolTest(config *aws.Config) *OutputService6ProtocolTest {
459-
if config == nil {
460-
config = &aws.Config{}
461-
}
462-
463439
service := &aws.Service{
464440
Config: aws.DefaultConfig.Merge(config),
465441
ServiceName: "outputservice6protocoltest",
@@ -521,7 +497,7 @@ type metadataOutputService6TestShapeOutputService6TestCaseOperation1Input struct
521497
}
522498

523499
type OutputService6TestShapeOutputShape struct {
524-
Map *map[string]*OutputService6TestShapeStructureType `type:"map"`
500+
Map map[string]*OutputService6TestShapeStructureType `type:"map"`
525501

526502
metadataOutputService6TestShapeOutputShape `json:"-" xml:"-"`
527503
}
@@ -547,10 +523,6 @@ type OutputService7ProtocolTest struct {
547523

548524
// New returns a new OutputService7ProtocolTest client.
549525
func NewOutputService7ProtocolTest(config *aws.Config) *OutputService7ProtocolTest {
550-
if config == nil {
551-
config = &aws.Config{}
552-
}
553-
554526
service := &aws.Service{
555527
Config: aws.DefaultConfig.Merge(config),
556528
ServiceName: "outputservice7protocoltest",
@@ -612,7 +584,7 @@ type metadataOutputService7TestShapeOutputService7TestCaseOperation1Input struct
612584
}
613585

614586
type OutputService7TestShapeOutputShape struct {
615-
Map *map[string]*string `type:"map" flattened:"true"`
587+
Map map[string]*string `type:"map" flattened:"true"`
616588

617589
metadataOutputService7TestShapeOutputShape `json:"-" xml:"-"`
618590
}
@@ -628,10 +600,6 @@ type OutputService8ProtocolTest struct {
628600

629601
// New returns a new OutputService8ProtocolTest client.
630602
func NewOutputService8ProtocolTest(config *aws.Config) *OutputService8ProtocolTest {
631-
if config == nil {
632-
config = &aws.Config{}
633-
}
634-
635603
service := &aws.Service{
636604
Config: aws.DefaultConfig.Merge(config),
637605
ServiceName: "outputservice8protocoltest",
@@ -693,7 +661,7 @@ type metadataOutputService8TestShapeOutputService8TestCaseOperation1Input struct
693661
}
694662

695663
type OutputService8TestShapeOutputShape struct {
696-
Map *map[string]*string `locationNameKey:"foo" locationNameValue:"bar" type:"map" flattened:"true"`
664+
Map map[string]*string `locationNameKey:"foo" locationNameValue:"bar" type:"map" flattened:"true"`
697665

698666
metadataOutputService8TestShapeOutputShape `json:"-" xml:"-"`
699667
}
@@ -832,8 +800,8 @@ func TestOutputService6ProtocolTestNormalMapCase1(t *testing.T) {
832800

833801
// assert response
834802
assert.NotNil(t, out) // ensure out variable is used
835-
assert.Equal(t, "bam", *(*out.Map)["baz"].Foo)
836-
assert.Equal(t, "bar", *(*out.Map)["qux"].Foo)
803+
assert.Equal(t, "bam", *out.Map["baz"].Foo)
804+
assert.Equal(t, "bar", *out.Map["qux"].Foo)
837805

838806
}
839807

@@ -853,8 +821,8 @@ func TestOutputService7ProtocolTestFlattenedMapCase1(t *testing.T) {
853821

854822
// assert response
855823
assert.NotNil(t, out) // ensure out variable is used
856-
assert.Equal(t, "bam", *(*out.Map)["baz"])
857-
assert.Equal(t, "bar", *(*out.Map)["qux"])
824+
assert.Equal(t, "bam", *out.Map["baz"])
825+
assert.Equal(t, "bar", *out.Map["qux"])
858826

859827
}
860828

@@ -874,7 +842,7 @@ func TestOutputService8ProtocolTestNamedMapCase1(t *testing.T) {
874842

875843
// assert response
876844
assert.NotNil(t, out) // ensure out variable is used
877-
assert.Equal(t, "bam", *(*out.Map)["baz"])
878-
assert.Equal(t, "bar", *(*out.Map)["qux"])
845+
assert.Equal(t, "bam", *out.Map["baz"])
846+
assert.Equal(t, "bar", *out.Map["qux"])
879847

880848
}

internal/protocol/json/jsonutil/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func buildStruct(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag)
7171
for i := 0; i < t.NumField(); i++ {
7272
field := t.Field(i)
7373
member := value.FieldByName(field.Name)
74-
if (member.Kind() == reflect.Ptr || member.Kind() == reflect.Slice) && member.IsNil() {
74+
if (member.Kind() == reflect.Ptr || member.Kind() == reflect.Slice || member.Kind() == reflect.Map) && member.IsNil() {
7575
continue // ignore unset fields
7676
}
7777
if c := field.Name[0:1]; strings.ToLower(c) == c {

internal/protocol/json/jsonutil/unmarshal.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,8 @@ func unmarshalMap(value reflect.Value, data interface{}, tag reflect.StructTag)
151151
return fmt.Errorf("JSON value is not a map (%#v)", data)
152152
}
153153

154-
t := value.Type()
155-
if value.Kind() == reflect.Ptr {
156-
t = t.Elem()
157-
if value.IsNil() {
158-
value.Set(reflect.New(t))
159-
value.Elem().Set(reflect.MakeMap(t))
160-
}
161-
162-
value = value.Elem()
154+
if value.IsNil() {
155+
value.Set(reflect.MakeMap(value.Type()))
163156
}
164157

165158
for k, v := range mapData {

0 commit comments

Comments
 (0)