1package appplatform
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/tracing"
14	"net/http"
15)
16
17// RuntimeVersionsClient is the REST API for Azure Spring Cloud
18type RuntimeVersionsClient struct {
19	BaseClient
20}
21
22// NewRuntimeVersionsClient creates an instance of the RuntimeVersionsClient client.
23func NewRuntimeVersionsClient(subscriptionID string) RuntimeVersionsClient {
24	return NewRuntimeVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewRuntimeVersionsClientWithBaseURI creates an instance of the RuntimeVersionsClient client using a custom endpoint.
28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewRuntimeVersionsClientWithBaseURI(baseURI string, subscriptionID string) RuntimeVersionsClient {
30	return RuntimeVersionsClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// ListRuntimeVersions lists all of the available runtime versions supported by Microsoft.AppPlatform provider.
34func (client RuntimeVersionsClient) ListRuntimeVersions(ctx context.Context) (result AvailableRuntimeVersions, err error) {
35	if tracing.IsEnabled() {
36		ctx = tracing.StartSpan(ctx, fqdn+"/RuntimeVersionsClient.ListRuntimeVersions")
37		defer func() {
38			sc := -1
39			if result.Response.Response != nil {
40				sc = result.Response.Response.StatusCode
41			}
42			tracing.EndSpan(ctx, sc, err)
43		}()
44	}
45	req, err := client.ListRuntimeVersionsPreparer(ctx)
46	if err != nil {
47		err = autorest.NewErrorWithError(err, "appplatform.RuntimeVersionsClient", "ListRuntimeVersions", nil, "Failure preparing request")
48		return
49	}
50
51	resp, err := client.ListRuntimeVersionsSender(req)
52	if err != nil {
53		result.Response = autorest.Response{Response: resp}
54		err = autorest.NewErrorWithError(err, "appplatform.RuntimeVersionsClient", "ListRuntimeVersions", resp, "Failure sending request")
55		return
56	}
57
58	result, err = client.ListRuntimeVersionsResponder(resp)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "appplatform.RuntimeVersionsClient", "ListRuntimeVersions", resp, "Failure responding to request")
61		return
62	}
63
64	return
65}
66
67// ListRuntimeVersionsPreparer prepares the ListRuntimeVersions request.
68func (client RuntimeVersionsClient) ListRuntimeVersionsPreparer(ctx context.Context) (*http.Request, error) {
69	const APIVersion = "2020-07-01"
70	queryParameters := map[string]interface{}{
71		"api-version": APIVersion,
72	}
73
74	preparer := autorest.CreatePreparer(
75		autorest.AsGet(),
76		autorest.WithBaseURL(client.BaseURI),
77		autorest.WithPath("/providers/Microsoft.AppPlatform/runtimeVersions"),
78		autorest.WithQueryParameters(queryParameters))
79	return preparer.Prepare((&http.Request{}).WithContext(ctx))
80}
81
82// ListRuntimeVersionsSender sends the ListRuntimeVersions request. The method will close the
83// http.Response Body if it receives an error.
84func (client RuntimeVersionsClient) ListRuntimeVersionsSender(req *http.Request) (*http.Response, error) {
85	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
86}
87
88// ListRuntimeVersionsResponder handles the response to the ListRuntimeVersions request. The method always
89// closes the http.Response Body.
90func (client RuntimeVersionsClient) ListRuntimeVersionsResponder(resp *http.Response) (result AvailableRuntimeVersions, err error) {
91	err = autorest.Respond(
92		resp,
93		azure.WithErrorUnlessStatusCode(http.StatusOK),
94		autorest.ByUnmarshallingJSON(&result),
95		autorest.ByClosing())
96	result.Response = autorest.Response{Response: resp}
97	return
98}
99