...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/appinsights/v1/insights/metadata.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/appinsights/v1/insights

     1  package insights
     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  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // MetadataClient is the composite Swagger for Application Insights Data Client
    18  type MetadataClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewMetadataClient creates an instance of the MetadataClient client.
    23  func NewMetadataClient() MetadataClient {
    24  	return NewMetadataClientWithBaseURI(DefaultBaseURI)
    25  }
    26  
    27  // NewMetadataClientWithBaseURI creates an instance of the MetadataClient client using a custom endpoint.  Use this
    28  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewMetadataClientWithBaseURI(baseURI string) MetadataClient {
    30  	return MetadataClient{NewWithBaseURI(baseURI)}
    31  }
    32  
    33  // Get retrieve the metadata information for the app, including its schema, etc.
    34  // Parameters:
    35  // appID - ID of the application. This is Application ID from the API Access settings blade in the Azure
    36  // portal.
    37  func (client MetadataClient) Get(ctx context.Context, appID string) (result MetadataResults, err error) {
    38  	if tracing.IsEnabled() {
    39  		ctx = tracing.StartSpan(ctx, fqdn+"/MetadataClient.Get")
    40  		defer func() {
    41  			sc := -1
    42  			if result.Response.Response != nil {
    43  				sc = result.Response.Response.StatusCode
    44  			}
    45  			tracing.EndSpan(ctx, sc, err)
    46  		}()
    47  	}
    48  	req, err := client.GetPreparer(ctx, appID)
    49  	if err != nil {
    50  		err = autorest.NewErrorWithError(err, "insights.MetadataClient", "Get", nil, "Failure preparing request")
    51  		return
    52  	}
    53  
    54  	resp, err := client.GetSender(req)
    55  	if err != nil {
    56  		result.Response = autorest.Response{Response: resp}
    57  		err = autorest.NewErrorWithError(err, "insights.MetadataClient", "Get", resp, "Failure sending request")
    58  		return
    59  	}
    60  
    61  	result, err = client.GetResponder(resp)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "insights.MetadataClient", "Get", resp, "Failure responding to request")
    64  		return
    65  	}
    66  
    67  	return
    68  }
    69  
    70  // GetPreparer prepares the Get request.
    71  func (client MetadataClient) GetPreparer(ctx context.Context, appID string) (*http.Request, error) {
    72  	pathParameters := map[string]interface{}{
    73  		"appId": autorest.Encode("path", appID),
    74  	}
    75  
    76  	preparer := autorest.CreatePreparer(
    77  		autorest.AsGet(),
    78  		autorest.WithBaseURL(client.BaseURI),
    79  		autorest.WithPathParameters("/apps/{appId}/metadata", pathParameters))
    80  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    81  }
    82  
    83  // GetSender sends the Get request. The method will close the
    84  // http.Response Body if it receives an error.
    85  func (client MetadataClient) GetSender(req *http.Request) (*http.Response, error) {
    86  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    87  }
    88  
    89  // GetResponder handles the response to the Get request. The method always
    90  // closes the http.Response Body.
    91  func (client MetadataClient) GetResponder(resp *http.Response) (result MetadataResults, err error) {
    92  	err = autorest.Respond(
    93  		resp,
    94  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    95  		autorest.ByUnmarshallingJSON(&result),
    96  		autorest.ByClosing())
    97  	result.Response = autorest.Response{Response: resp}
    98  	return
    99  }
   100  
   101  // Post retrieve the metadata information for the app, including its schema, etc.
   102  // Parameters:
   103  // appID - ID of the application. This is Application ID from the API Access settings blade in the Azure
   104  // portal.
   105  func (client MetadataClient) Post(ctx context.Context, appID string) (result MetadataResults, err error) {
   106  	if tracing.IsEnabled() {
   107  		ctx = tracing.StartSpan(ctx, fqdn+"/MetadataClient.Post")
   108  		defer func() {
   109  			sc := -1
   110  			if result.Response.Response != nil {
   111  				sc = result.Response.Response.StatusCode
   112  			}
   113  			tracing.EndSpan(ctx, sc, err)
   114  		}()
   115  	}
   116  	req, err := client.PostPreparer(ctx, appID)
   117  	if err != nil {
   118  		err = autorest.NewErrorWithError(err, "insights.MetadataClient", "Post", nil, "Failure preparing request")
   119  		return
   120  	}
   121  
   122  	resp, err := client.PostSender(req)
   123  	if err != nil {
   124  		result.Response = autorest.Response{Response: resp}
   125  		err = autorest.NewErrorWithError(err, "insights.MetadataClient", "Post", resp, "Failure sending request")
   126  		return
   127  	}
   128  
   129  	result, err = client.PostResponder(resp)
   130  	if err != nil {
   131  		err = autorest.NewErrorWithError(err, "insights.MetadataClient", "Post", resp, "Failure responding to request")
   132  		return
   133  	}
   134  
   135  	return
   136  }
   137  
   138  // PostPreparer prepares the Post request.
   139  func (client MetadataClient) PostPreparer(ctx context.Context, appID string) (*http.Request, error) {
   140  	pathParameters := map[string]interface{}{
   141  		"appId": autorest.Encode("path", appID),
   142  	}
   143  
   144  	preparer := autorest.CreatePreparer(
   145  		autorest.AsPost(),
   146  		autorest.WithBaseURL(client.BaseURI),
   147  		autorest.WithPathParameters("/apps/{appId}/metadata", pathParameters))
   148  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   149  }
   150  
   151  // PostSender sends the Post request. The method will close the
   152  // http.Response Body if it receives an error.
   153  func (client MetadataClient) PostSender(req *http.Request) (*http.Response, error) {
   154  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   155  }
   156  
   157  // PostResponder handles the response to the Post request. The method always
   158  // closes the http.Response Body.
   159  func (client MetadataClient) PostResponder(resp *http.Response) (result MetadataResults, err error) {
   160  	err = autorest.Respond(
   161  		resp,
   162  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   163  		autorest.ByUnmarshallingJSON(&result),
   164  		autorest.ByClosing())
   165  	result.Response = autorest.Response{Response: resp}
   166  	return
   167  }
   168  

View as plain text