-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vpcs: Support listing members of a VPC. #439
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ type VPCsService interface { | |
Create(context.Context, *VPCCreateRequest) (*VPC, *Response, error) | ||
Get(context.Context, string) (*VPC, *Response, error) | ||
List(context.Context, *ListOptions) ([]*VPC, *Response, error) | ||
ListMembers(context.Context, string, *VPCListMembersRequest, *ListOptions) ([]*VPCMember, *Response, error) | ||
Update(context.Context, string, *VPCUpdateRequest) (*VPC, *Response, error) | ||
Set(context.Context, string, ...VPCSetField) (*VPC, *Response, error) | ||
Delete(context.Context, string) (*Response, error) | ||
|
@@ -77,6 +78,16 @@ type VPC struct { | |
Default bool `json:"default,omitempty"` | ||
} | ||
|
||
type VPCListMembersRequest struct { | ||
ResourceType string `url:"resource_type,omitempty"` | ||
} | ||
|
||
type VPCMember struct { | ||
URN string `json:"urn,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
CreatedAt time.Time `json:"created_at,omitempty"` | ||
} | ||
|
||
type vpcRoot struct { | ||
VPC *VPC `json:"vpc"` | ||
} | ||
|
@@ -87,6 +98,12 @@ type vpcsRoot struct { | |
Meta *Meta `json:"meta"` | ||
} | ||
|
||
type vpcMembersRoot struct { | ||
Members []*VPCMember `json:"members"` | ||
Links *Links `json:"links"` | ||
Meta *Meta `json:"meta"` | ||
} | ||
|
||
// Get returns the details of a Virtual Private Cloud. | ||
func (v *VPCsServiceOp) Get(ctx context.Context, id string) (*VPC, *Response, error) { | ||
path := vpcsBasePath + "/" + id | ||
|
@@ -214,3 +231,35 @@ func (v *VPCsServiceOp) Delete(ctx context.Context, id string) (*Response, error | |
|
||
return resp, nil | ||
} | ||
|
||
func (v *VPCsServiceOp) ListMembers(ctx context.Context, id string, request *VPCListMembersRequest, opt *ListOptions) ([]*VPCMember, *Response, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golang question: Is it a paradigm that interface functions return pointers and not actual values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily, but it's the general pattern we're using in godo. |
||
path := vpcsBasePath + "/" + id + "/members" | ||
pathWithResourceType, err := addOptions(path, request) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
pathWithOpts, err := addOptions(pathWithResourceType, opt) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := v.client.NewRequest(ctx, http.MethodGet, pathWithOpts, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
root := new(vpcMembersRoot) | ||
resp, err := v.client.Do(ctx, req, root) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
if l := root.Links; l != nil { | ||
resp.Links = l | ||
} | ||
if m := root.Meta; m != nil { | ||
resp.Meta = m | ||
} | ||
|
||
return root.Members, resp, nil | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it's never been implemented!