1// +build go1.13 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armapimanagement 9 10import ( 11 "context" 12 "errors" 13 "fmt" 14 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 16 "net/http" 17 "net/url" 18 "strconv" 19 "strings" 20) 21 22// UserGroupClient contains the methods for the UserGroup group. 23// Don't use this type directly, use NewUserGroupClient() instead. 24type UserGroupClient struct { 25 con *armcore.Connection 26 subscriptionID string 27} 28 29// NewUserGroupClient creates a new instance of UserGroupClient with the specified values. 30func NewUserGroupClient(con *armcore.Connection, subscriptionID string) *UserGroupClient { 31 return &UserGroupClient{con: con, subscriptionID: subscriptionID} 32} 33 34// List - Lists all user groups. 35// If the operation fails it returns the *ErrorResponse error type. 36func (client *UserGroupClient) List(resourceGroupName string, serviceName string, userID string, options *UserGroupListOptions) UserGroupListPager { 37 return &userGroupListPager{ 38 client: client, 39 requester: func(ctx context.Context) (*azcore.Request, error) { 40 return client.listCreateRequest(ctx, resourceGroupName, serviceName, userID, options) 41 }, 42 advancer: func(ctx context.Context, resp UserGroupListResponse) (*azcore.Request, error) { 43 return azcore.NewRequest(ctx, http.MethodGet, *resp.GroupCollection.NextLink) 44 }, 45 } 46} 47 48// listCreateRequest creates the List request. 49func (client *UserGroupClient) listCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, userID string, options *UserGroupListOptions) (*azcore.Request, error) { 50 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{userId}/groups" 51 if resourceGroupName == "" { 52 return nil, errors.New("parameter resourceGroupName cannot be empty") 53 } 54 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 55 if serviceName == "" { 56 return nil, errors.New("parameter serviceName cannot be empty") 57 } 58 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 59 if userID == "" { 60 return nil, errors.New("parameter userID cannot be empty") 61 } 62 urlPath = strings.ReplaceAll(urlPath, "{userId}", url.PathEscape(userID)) 63 if client.subscriptionID == "" { 64 return nil, errors.New("parameter client.subscriptionID cannot be empty") 65 } 66 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 67 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 68 if err != nil { 69 return nil, err 70 } 71 req.Telemetry(telemetryInfo) 72 reqQP := req.URL.Query() 73 if options != nil && options.Filter != nil { 74 reqQP.Set("$filter", *options.Filter) 75 } 76 if options != nil && options.Top != nil { 77 reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) 78 } 79 if options != nil && options.Skip != nil { 80 reqQP.Set("$skip", strconv.FormatInt(int64(*options.Skip), 10)) 81 } 82 reqQP.Set("api-version", "2020-12-01") 83 req.URL.RawQuery = reqQP.Encode() 84 req.Header.Set("Accept", "application/json") 85 return req, nil 86} 87 88// listHandleResponse handles the List response. 89func (client *UserGroupClient) listHandleResponse(resp *azcore.Response) (UserGroupListResponse, error) { 90 result := UserGroupListResponse{RawResponse: resp.Response} 91 if err := resp.UnmarshalAsJSON(&result.GroupCollection); err != nil { 92 return UserGroupListResponse{}, err 93 } 94 return result, nil 95} 96 97// listHandleError handles the List error response. 98func (client *UserGroupClient) listHandleError(resp *azcore.Response) error { 99 body, err := resp.Payload() 100 if err != nil { 101 return azcore.NewResponseError(err, resp.Response) 102 } 103 errType := ErrorResponse{raw: string(body)} 104 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 105 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 106 } 107 return azcore.NewResponseError(&errType, resp.Response) 108} 109