Skip to content

Commit

Permalink
fix: use struct instead of using pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
zhekazuev committed Jan 19, 2024
1 parent 52a3433 commit 0b8b1e1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions openstack/db/v1/instances/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type CreateOpts struct {
// Networks dictates how this server will be attached to available networks.
Networks []NetworkOpts
// A access object defines how the database service is exposed. Optional.
Access *AccessOpts `json:"access,omitempty"`
Access AccessOpts `json:"access,omitempty"`
}

// ToInstanceCreateMap will render a JSON map.
Expand Down Expand Up @@ -148,7 +148,8 @@ func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
instance["nics"] = networks
}

if opts.Access != nil {
// Add check for opts.Access
if opts.Access.IsPublic || len(opts.Access.AllowedCIDR) > 0 {
access, err := opts.Access.ToMap()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion openstack/db/v1/instances/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type Instance struct {
Addresses []Address

// Controls database service exposing.
Access *AccessOpts
Access AccessOpts
}

func (r *Instance) UnmarshalJSON(b []byte) error {
Expand Down
4 changes: 2 additions & 2 deletions openstack/db/v1/instances/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ var expectedInstance = instances.Instance{
Type: "mysql",
Version: "5.6",
},
Access: &instances.AccessOpts{
Access: instances.AccessOpts{
IsPublic: true,
AllowedCIDR: []string{"202.78.240.0/24"},
},
Expand Down Expand Up @@ -271,7 +271,7 @@ var expectedGetInstance = instances.Instance{
{Type: "private", Address: "10.1.0.62"},
{Type: "public", Address: "172.24.5.114"},
},
Access: &instances.AccessOpts{
Access: instances.AccessOpts{
IsPublic: true,
AllowedCIDR: []string{"202.78.240.0/24"},
},
Expand Down
4 changes: 2 additions & 2 deletions openstack/db/v1/instances/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCreate(t *testing.T) {
},
Size: 2,
VolumeType: "ssd",
Access: &instances.AccessOpts{
Access: instances.AccessOpts{
IsPublic: true,
AllowedCIDR: []string{"202.78.240.0/24"},
},
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestCreateWithFault(t *testing.T) {
},
Size: 2,
VolumeType: "ssd",
Access: &instances.AccessOpts{
Access: instances.AccessOpts{
IsPublic: true,
AllowedCIDR: []string{"202.78.240.0/24"},
},
Expand Down

0 comments on commit 0b8b1e1

Please sign in to comment.