github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/routes_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // RoutesClient contains the methods for the Routes group. 24 // Don't use this type directly, use NewRoutesClient() instead. 25 type RoutesClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewRoutesClient creates a new instance of RoutesClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewRoutesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*RoutesClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &RoutesClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates or updates a route in the specified route table. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - routeTableName - The name of the route table. 53 // - routeName - The name of the route. 54 // - routeParameters - Parameters supplied to the create or update route operation. 55 // - options - RoutesClientBeginCreateOrUpdateOptions contains the optional parameters for the RoutesClient.BeginCreateOrUpdate 56 // method. 57 func (client *RoutesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters Route, options *RoutesClientBeginCreateOrUpdateOptions) (*runtime.Poller[RoutesClientCreateOrUpdateResponse], error) { 58 if options == nil || options.ResumeToken == "" { 59 resp, err := client.createOrUpdate(ctx, resourceGroupName, routeTableName, routeName, routeParameters, options) 60 if err != nil { 61 return nil, err 62 } 63 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutesClientCreateOrUpdateResponse]{ 64 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 65 Tracer: client.internal.Tracer(), 66 }) 67 return poller, err 68 } else { 69 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[RoutesClientCreateOrUpdateResponse]{ 70 Tracer: client.internal.Tracer(), 71 }) 72 } 73 } 74 75 // CreateOrUpdate - Creates or updates a route in the specified route table. 76 // If the operation fails it returns an *azcore.ResponseError type. 77 // 78 // Generated from API version 2024-05-01 79 func (client *RoutesClient) createOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters Route, options *RoutesClientBeginCreateOrUpdateOptions) (*http.Response, error) { 80 var err error 81 const operationName = "RoutesClient.BeginCreateOrUpdate" 82 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 83 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 84 defer func() { endSpan(err) }() 85 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, routeTableName, routeName, routeParameters, options) 86 if err != nil { 87 return nil, err 88 } 89 httpResp, err := client.internal.Pipeline().Do(req) 90 if err != nil { 91 return nil, err 92 } 93 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 94 err = runtime.NewResponseError(httpResp) 95 return nil, err 96 } 97 return httpResp, nil 98 } 99 100 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 101 func (client *RoutesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters Route, options *RoutesClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 102 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes/{routeName}" 103 if resourceGroupName == "" { 104 return nil, errors.New("parameter resourceGroupName cannot be empty") 105 } 106 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 107 if routeTableName == "" { 108 return nil, errors.New("parameter routeTableName cannot be empty") 109 } 110 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 111 if routeName == "" { 112 return nil, errors.New("parameter routeName cannot be empty") 113 } 114 urlPath = strings.ReplaceAll(urlPath, "{routeName}", url.PathEscape(routeName)) 115 if client.subscriptionID == "" { 116 return nil, errors.New("parameter client.subscriptionID cannot be empty") 117 } 118 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 119 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 120 if err != nil { 121 return nil, err 122 } 123 reqQP := req.Raw().URL.Query() 124 reqQP.Set("api-version", "2024-05-01") 125 req.Raw().URL.RawQuery = reqQP.Encode() 126 req.Raw().Header["Accept"] = []string{"application/json"} 127 if err := runtime.MarshalAsJSON(req, routeParameters); err != nil { 128 return nil, err 129 } 130 return req, nil 131 } 132 133 // BeginDelete - Deletes the specified route from a route table. 134 // If the operation fails it returns an *azcore.ResponseError type. 135 // 136 // Generated from API version 2024-05-01 137 // - resourceGroupName - The name of the resource group. 138 // - routeTableName - The name of the route table. 139 // - routeName - The name of the route. 140 // - options - RoutesClientBeginDeleteOptions contains the optional parameters for the RoutesClient.BeginDelete method. 141 func (client *RoutesClient) BeginDelete(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientBeginDeleteOptions) (*runtime.Poller[RoutesClientDeleteResponse], error) { 142 if options == nil || options.ResumeToken == "" { 143 resp, err := client.deleteOperation(ctx, resourceGroupName, routeTableName, routeName, options) 144 if err != nil { 145 return nil, err 146 } 147 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RoutesClientDeleteResponse]{ 148 FinalStateVia: runtime.FinalStateViaLocation, 149 Tracer: client.internal.Tracer(), 150 }) 151 return poller, err 152 } else { 153 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[RoutesClientDeleteResponse]{ 154 Tracer: client.internal.Tracer(), 155 }) 156 } 157 } 158 159 // Delete - Deletes the specified route from a route table. 160 // If the operation fails it returns an *azcore.ResponseError type. 161 // 162 // Generated from API version 2024-05-01 163 func (client *RoutesClient) deleteOperation(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientBeginDeleteOptions) (*http.Response, error) { 164 var err error 165 const operationName = "RoutesClient.BeginDelete" 166 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 167 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 168 defer func() { endSpan(err) }() 169 req, err := client.deleteCreateRequest(ctx, resourceGroupName, routeTableName, routeName, options) 170 if err != nil { 171 return nil, err 172 } 173 httpResp, err := client.internal.Pipeline().Do(req) 174 if err != nil { 175 return nil, err 176 } 177 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 178 err = runtime.NewResponseError(httpResp) 179 return nil, err 180 } 181 return httpResp, nil 182 } 183 184 // deleteCreateRequest creates the Delete request. 185 func (client *RoutesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientBeginDeleteOptions) (*policy.Request, error) { 186 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes/{routeName}" 187 if resourceGroupName == "" { 188 return nil, errors.New("parameter resourceGroupName cannot be empty") 189 } 190 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 191 if routeTableName == "" { 192 return nil, errors.New("parameter routeTableName cannot be empty") 193 } 194 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 195 if routeName == "" { 196 return nil, errors.New("parameter routeName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{routeName}", url.PathEscape(routeName)) 199 if client.subscriptionID == "" { 200 return nil, errors.New("parameter client.subscriptionID cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 203 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 204 if err != nil { 205 return nil, err 206 } 207 reqQP := req.Raw().URL.Query() 208 reqQP.Set("api-version", "2024-05-01") 209 req.Raw().URL.RawQuery = reqQP.Encode() 210 req.Raw().Header["Accept"] = []string{"application/json"} 211 return req, nil 212 } 213 214 // Get - Gets the specified route from a route table. 215 // If the operation fails it returns an *azcore.ResponseError type. 216 // 217 // Generated from API version 2024-05-01 218 // - resourceGroupName - The name of the resource group. 219 // - routeTableName - The name of the route table. 220 // - routeName - The name of the route. 221 // - options - RoutesClientGetOptions contains the optional parameters for the RoutesClient.Get method. 222 func (client *RoutesClient) Get(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientGetOptions) (RoutesClientGetResponse, error) { 223 var err error 224 const operationName = "RoutesClient.Get" 225 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 226 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 227 defer func() { endSpan(err) }() 228 req, err := client.getCreateRequest(ctx, resourceGroupName, routeTableName, routeName, options) 229 if err != nil { 230 return RoutesClientGetResponse{}, err 231 } 232 httpResp, err := client.internal.Pipeline().Do(req) 233 if err != nil { 234 return RoutesClientGetResponse{}, err 235 } 236 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 237 err = runtime.NewResponseError(httpResp) 238 return RoutesClientGetResponse{}, err 239 } 240 resp, err := client.getHandleResponse(httpResp) 241 return resp, err 242 } 243 244 // getCreateRequest creates the Get request. 245 func (client *RoutesClient) getCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, options *RoutesClientGetOptions) (*policy.Request, error) { 246 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes/{routeName}" 247 if resourceGroupName == "" { 248 return nil, errors.New("parameter resourceGroupName cannot be empty") 249 } 250 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 251 if routeTableName == "" { 252 return nil, errors.New("parameter routeTableName cannot be empty") 253 } 254 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 255 if routeName == "" { 256 return nil, errors.New("parameter routeName cannot be empty") 257 } 258 urlPath = strings.ReplaceAll(urlPath, "{routeName}", url.PathEscape(routeName)) 259 if client.subscriptionID == "" { 260 return nil, errors.New("parameter client.subscriptionID cannot be empty") 261 } 262 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 263 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 264 if err != nil { 265 return nil, err 266 } 267 reqQP := req.Raw().URL.Query() 268 reqQP.Set("api-version", "2024-05-01") 269 req.Raw().URL.RawQuery = reqQP.Encode() 270 req.Raw().Header["Accept"] = []string{"application/json"} 271 return req, nil 272 } 273 274 // getHandleResponse handles the Get response. 275 func (client *RoutesClient) getHandleResponse(resp *http.Response) (RoutesClientGetResponse, error) { 276 result := RoutesClientGetResponse{} 277 if err := runtime.UnmarshalAsJSON(resp, &result.Route); err != nil { 278 return RoutesClientGetResponse{}, err 279 } 280 return result, nil 281 } 282 283 // NewListPager - Gets all routes in a route table. 284 // 285 // Generated from API version 2024-05-01 286 // - resourceGroupName - The name of the resource group. 287 // - routeTableName - The name of the route table. 288 // - options - RoutesClientListOptions contains the optional parameters for the RoutesClient.NewListPager method. 289 func (client *RoutesClient) NewListPager(resourceGroupName string, routeTableName string, options *RoutesClientListOptions) *runtime.Pager[RoutesClientListResponse] { 290 return runtime.NewPager(runtime.PagingHandler[RoutesClientListResponse]{ 291 More: func(page RoutesClientListResponse) bool { 292 return page.NextLink != nil && len(*page.NextLink) > 0 293 }, 294 Fetcher: func(ctx context.Context, page *RoutesClientListResponse) (RoutesClientListResponse, error) { 295 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RoutesClient.NewListPager") 296 nextLink := "" 297 if page != nil { 298 nextLink = *page.NextLink 299 } 300 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 301 return client.listCreateRequest(ctx, resourceGroupName, routeTableName, options) 302 }, nil) 303 if err != nil { 304 return RoutesClientListResponse{}, err 305 } 306 return client.listHandleResponse(resp) 307 }, 308 Tracer: client.internal.Tracer(), 309 }) 310 } 311 312 // listCreateRequest creates the List request. 313 func (client *RoutesClient) listCreateRequest(ctx context.Context, resourceGroupName string, routeTableName string, options *RoutesClientListOptions) (*policy.Request, error) { 314 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/routeTables/{routeTableName}/routes" 315 if resourceGroupName == "" { 316 return nil, errors.New("parameter resourceGroupName cannot be empty") 317 } 318 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 319 if routeTableName == "" { 320 return nil, errors.New("parameter routeTableName cannot be empty") 321 } 322 urlPath = strings.ReplaceAll(urlPath, "{routeTableName}", url.PathEscape(routeTableName)) 323 if client.subscriptionID == "" { 324 return nil, errors.New("parameter client.subscriptionID cannot be empty") 325 } 326 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 327 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 328 if err != nil { 329 return nil, err 330 } 331 reqQP := req.Raw().URL.Query() 332 reqQP.Set("api-version", "2024-05-01") 333 req.Raw().URL.RawQuery = reqQP.Encode() 334 req.Raw().Header["Accept"] = []string{"application/json"} 335 return req, nil 336 } 337 338 // listHandleResponse handles the List response. 339 func (client *RoutesClient) listHandleResponse(resp *http.Response) (RoutesClientListResponse, error) { 340 result := RoutesClientListResponse{} 341 if err := runtime.UnmarshalAsJSON(resp, &result.RouteListResult); err != nil { 342 return RoutesClientListResponse{}, err 343 } 344 return result, nil 345 }