...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl/costs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl

     1  package dtl
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // CostsClient is the the DevTest Labs Client.
    19  type CostsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCostsClient creates an instance of the CostsClient client.
    24  func NewCostsClient(subscriptionID string) CostsClient {
    25  	return NewCostsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewCostsClientWithBaseURI creates an instance of the CostsClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewCostsClientWithBaseURI(baseURI string, subscriptionID string) CostsClient {
    31  	return CostsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or replace an existing cost.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // labName - the name of the lab.
    38  // name - the name of the cost.
    39  // labCost - a cost item.
    40  func (client CostsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, labCost LabCost) (result LabCost, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/CostsClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: labCost,
    53  			Constraints: []validation.Constraint{{Target: "labCost.LabCostProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    54  		return result, validation.NewError("dtl.CostsClient", "CreateOrUpdate", err.Error())
    55  	}
    56  
    57  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, labCost)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "dtl.CostsClient", "CreateOrUpdate", nil, "Failure preparing request")
    60  		return
    61  	}
    62  
    63  	resp, err := client.CreateOrUpdateSender(req)
    64  	if err != nil {
    65  		result.Response = autorest.Response{Response: resp}
    66  		err = autorest.NewErrorWithError(err, "dtl.CostsClient", "CreateOrUpdate", resp, "Failure sending request")
    67  		return
    68  	}
    69  
    70  	result, err = client.CreateOrUpdateResponder(resp)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "dtl.CostsClient", "CreateOrUpdate", resp, "Failure responding to request")
    73  		return
    74  	}
    75  
    76  	return
    77  }
    78  
    79  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    80  func (client CostsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labCost LabCost) (*http.Request, error) {
    81  	pathParameters := map[string]interface{}{
    82  		"labName":           autorest.Encode("path", labName),
    83  		"name":              autorest.Encode("path", name),
    84  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    85  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    86  	}
    87  
    88  	const APIVersion = "2018-09-15"
    89  	queryParameters := map[string]interface{}{
    90  		"api-version": APIVersion,
    91  	}
    92  
    93  	preparer := autorest.CreatePreparer(
    94  		autorest.AsContentType("application/json; charset=utf-8"),
    95  		autorest.AsPut(),
    96  		autorest.WithBaseURL(client.BaseURI),
    97  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}", pathParameters),
    98  		autorest.WithJSON(labCost),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client CostsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   106  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   107  }
   108  
   109  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   110  // closes the http.Response Body.
   111  func (client CostsClient) CreateOrUpdateResponder(resp *http.Response) (result LabCost, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // Get get cost.
   122  // Parameters:
   123  // resourceGroupName - the name of the resource group.
   124  // labName - the name of the lab.
   125  // name - the name of the cost.
   126  // expand - specify the $expand query. Example: 'properties($expand=labCostDetails)'
   127  func (client CostsClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result LabCost, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/CostsClient.Get")
   130  		defer func() {
   131  			sc := -1
   132  			if result.Response.Response != nil {
   133  				sc = result.Response.Response.StatusCode
   134  			}
   135  			tracing.EndSpan(ctx, sc, err)
   136  		}()
   137  	}
   138  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "dtl.CostsClient", "Get", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.GetSender(req)
   145  	if err != nil {
   146  		result.Response = autorest.Response{Response: resp}
   147  		err = autorest.NewErrorWithError(err, "dtl.CostsClient", "Get", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result, err = client.GetResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "dtl.CostsClient", "Get", resp, "Failure responding to request")
   154  		return
   155  	}
   156  
   157  	return
   158  }
   159  
   160  // GetPreparer prepares the Get request.
   161  func (client CostsClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
   162  	pathParameters := map[string]interface{}{
   163  		"labName":           autorest.Encode("path", labName),
   164  		"name":              autorest.Encode("path", name),
   165  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   166  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   167  	}
   168  
   169  	const APIVersion = "2018-09-15"
   170  	queryParameters := map[string]interface{}{
   171  		"api-version": APIVersion,
   172  	}
   173  	if len(expand) > 0 {
   174  		queryParameters["$expand"] = autorest.Encode("query", expand)
   175  	}
   176  
   177  	preparer := autorest.CreatePreparer(
   178  		autorest.AsGet(),
   179  		autorest.WithBaseURL(client.BaseURI),
   180  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}", pathParameters),
   181  		autorest.WithQueryParameters(queryParameters))
   182  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   183  }
   184  
   185  // GetSender sends the Get request. The method will close the
   186  // http.Response Body if it receives an error.
   187  func (client CostsClient) GetSender(req *http.Request) (*http.Response, error) {
   188  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   189  }
   190  
   191  // GetResponder handles the response to the Get request. The method always
   192  // closes the http.Response Body.
   193  func (client CostsClient) GetResponder(resp *http.Response) (result LabCost, err error) {
   194  	err = autorest.Respond(
   195  		resp,
   196  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   197  		autorest.ByUnmarshallingJSON(&result),
   198  		autorest.ByClosing())
   199  	result.Response = autorest.Response{Response: resp}
   200  	return
   201  }
   202  

View as plain text