1package apimanagement 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// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// APIExportClient is the apiManagement Client 19type APIExportClient struct { 20 BaseClient 21} 22 23// NewAPIExportClient creates an instance of the APIExportClient client. 24func NewAPIExportClient(subscriptionID string) APIExportClient { 25 return NewAPIExportClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewAPIExportClientWithBaseURI creates an instance of the APIExportClient client using a custom endpoint. Use this 29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewAPIExportClientWithBaseURI(baseURI string, subscriptionID string) APIExportClient { 31 return APIExportClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// Get gets the details of the API specified by its identifier. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// serviceName - the name of the API Management service. 38// apiid - API identifier. Must be unique in the current API Management service instance. 39func (client APIExportClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (result APIExportResult, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/APIExportClient.Get") 42 defer func() { 43 sc := -1 44 if result.Response.Response != nil { 45 sc = result.Response.Response.StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: serviceName, 52 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 53 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 54 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 55 {TargetValue: apiid, 56 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 57 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 59 return result, validation.NewError("apimanagement.APIExportClient", "Get", err.Error()) 60 } 61 62 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.GetSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.GetResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// GetPreparer prepares the Get request. 85func (client APIExportClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "apiId": autorest.Encode("path", apiid), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "serviceName": autorest.Encode("path", serviceName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 } 92 93 const APIVersion = "2016-10-10" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsGet(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// GetSender sends the Get request. The method will close the 107// http.Response Body if it receives an error. 108func (client APIExportClient) GetSender(req *http.Request) (*http.Response, error) { 109 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110} 111 112// GetResponder handles the response to the Get request. The method always 113// closes the http.Response Body. 114func (client APIExportClient) GetResponder(resp *http.Response) (result APIExportResult, err error) { 115 err = autorest.Respond( 116 resp, 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123