1package apimanagement 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// APIExportClient is the client for the APIExport methods of the Apimanagement service. 30type APIExportClient struct { 31 BaseClient 32} 33 34// NewAPIExportClient creates an instance of the APIExportClient client. 35func NewAPIExportClient() APIExportClient { 36 return APIExportClient{New()} 37} 38 39// Get gets the details of the API specified by its identifier in the format specified to the Storage Blob with SAS Key 40// valid for 5 minutes. 41// Parameters: 42// apimBaseURL - the management endpoint of the API Management service, for example 43// https://myapimservice.management.azure-api.net. 44// apiid - API identifier. Must be unique in the current API Management service instance. 45func (client APIExportClient) Get(ctx context.Context, apimBaseURL string, apiid string) (result APIExportResult, err error) { 46 if tracing.IsEnabled() { 47 ctx = tracing.StartSpan(ctx, fqdn+"/APIExportClient.Get") 48 defer func() { 49 sc := -1 50 if result.Response.Response != nil { 51 sc = result.Response.Response.StatusCode 52 } 53 tracing.EndSpan(ctx, sc, err) 54 }() 55 } 56 if err := validation.Validate([]validation.Validation{ 57 {TargetValue: apiid, 58 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 59 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 60 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 61 return result, validation.NewError("apimanagement.APIExportClient", "Get", err.Error()) 62 } 63 64 req, err := client.GetPreparer(ctx, apimBaseURL, apiid) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.GetSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.GetResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "apimanagement.APIExportClient", "Get", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// GetPreparer prepares the Get request. 87func (client APIExportClient) GetPreparer(ctx context.Context, apimBaseURL string, apiid string) (*http.Request, error) { 88 urlParameters := map[string]interface{}{ 89 "apimBaseUrl": apimBaseURL, 90 } 91 92 pathParameters := map[string]interface{}{ 93 "apiId": autorest.Encode("path", apiid), 94 } 95 96 const APIVersion = "2017-03-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 "export": autorest.Encode("query", "true"), 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsGet(), 104 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 105 autorest.WithPathParameters("/apis/{apiId}", pathParameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// GetSender sends the Get request. The method will close the 111// http.Response Body if it receives an error. 112func (client APIExportClient) GetSender(req *http.Request) (*http.Response, error) { 113 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 114} 115 116// GetResponder handles the response to the Get request. The method always 117// closes the http.Response Body. 118func (client APIExportClient) GetResponder(resp *http.Response) (result APIExportResult, err error) { 119 err = autorest.Respond( 120 resp, 121 azure.WithErrorUnlessStatusCode(http.StatusOK), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127