1package servicefabric 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// MeshGatewayClient is the service Fabric REST Client APIs allows management of Service Fabric clusters, applications 19// and services. 20type MeshGatewayClient struct { 21 BaseClient 22} 23 24// NewMeshGatewayClient creates an instance of the MeshGatewayClient client. 25func NewMeshGatewayClient() MeshGatewayClient { 26 return NewMeshGatewayClientWithBaseURI(DefaultBaseURI) 27} 28 29// NewMeshGatewayClientWithBaseURI creates an instance of the MeshGatewayClient client using a custom endpoint. Use 30// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 31func NewMeshGatewayClientWithBaseURI(baseURI string) MeshGatewayClient { 32 return MeshGatewayClient{NewWithBaseURI(baseURI)} 33} 34 35// CreateOrUpdate creates a Gateway resource with the specified name, description and properties. If Gateway resource 36// with the same name exists, then it is updated with the specified description and properties. Use Gateway resource to 37// provide public connectivity to application services. 38// Parameters: 39// gatewayResourceName - the identity of the gateway. 40// gatewayResourceDescription - description for creating a Gateway resource. 41func (client MeshGatewayClient) CreateOrUpdate(ctx context.Context, gatewayResourceName string, gatewayResourceDescription GatewayResourceDescription) (result GatewayResourceDescription, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/MeshGatewayClient.CreateOrUpdate") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: gatewayResourceDescription, 54 Constraints: []validation.Constraint{{Target: "gatewayResourceDescription.Name", Name: validation.Null, Rule: true, Chain: nil}, 55 {Target: "gatewayResourceDescription.GatewayProperties", Name: validation.Null, Rule: true, 56 Chain: []validation.Constraint{{Target: "gatewayResourceDescription.GatewayProperties.SourceNetwork", Name: validation.Null, Rule: true, Chain: nil}, 57 {Target: "gatewayResourceDescription.GatewayProperties.DestinationNetwork", Name: validation.Null, Rule: true, Chain: nil}, 58 }}}}}); err != nil { 59 return result, validation.NewError("servicefabric.MeshGatewayClient", "CreateOrUpdate", err.Error()) 60 } 61 62 req, err := client.CreateOrUpdatePreparer(ctx, gatewayResourceName, gatewayResourceDescription) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "CreateOrUpdate", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.CreateOrUpdateSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "CreateOrUpdate", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.CreateOrUpdateResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "CreateOrUpdate", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 85func (client MeshGatewayClient) CreateOrUpdatePreparer(ctx context.Context, gatewayResourceName string, gatewayResourceDescription GatewayResourceDescription) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "gatewayResourceName": gatewayResourceName, 88 } 89 90 const APIVersion = "6.4-preview" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsContentType("application/json; charset=utf-8"), 97 autorest.AsPut(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/Resources/Gateways/{gatewayResourceName}", pathParameters), 100 autorest.WithJSON(gatewayResourceDescription), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 106// http.Response Body if it receives an error. 107func (client MeshGatewayClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 108 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 109} 110 111// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 112// closes the http.Response Body. 113func (client MeshGatewayClient) CreateOrUpdateResponder(resp *http.Response) (result GatewayResourceDescription, err error) { 114 err = autorest.Respond( 115 resp, 116 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 117 autorest.ByUnmarshallingJSON(&result), 118 autorest.ByClosing()) 119 result.Response = autorest.Response{Response: resp} 120 return 121} 122 123// Delete deletes the Gateway resource identified by the name. 124// Parameters: 125// gatewayResourceName - the identity of the gateway. 126func (client MeshGatewayClient) Delete(ctx context.Context, gatewayResourceName string) (result autorest.Response, err error) { 127 if tracing.IsEnabled() { 128 ctx = tracing.StartSpan(ctx, fqdn+"/MeshGatewayClient.Delete") 129 defer func() { 130 sc := -1 131 if result.Response != nil { 132 sc = result.Response.StatusCode 133 } 134 tracing.EndSpan(ctx, sc, err) 135 }() 136 } 137 req, err := client.DeletePreparer(ctx, gatewayResourceName) 138 if err != nil { 139 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "Delete", nil, "Failure preparing request") 140 return 141 } 142 143 resp, err := client.DeleteSender(req) 144 if err != nil { 145 result.Response = resp 146 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "Delete", resp, "Failure sending request") 147 return 148 } 149 150 result, err = client.DeleteResponder(resp) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "Delete", resp, "Failure responding to request") 153 return 154 } 155 156 return 157} 158 159// DeletePreparer prepares the Delete request. 160func (client MeshGatewayClient) DeletePreparer(ctx context.Context, gatewayResourceName string) (*http.Request, error) { 161 pathParameters := map[string]interface{}{ 162 "gatewayResourceName": gatewayResourceName, 163 } 164 165 const APIVersion = "6.4-preview" 166 queryParameters := map[string]interface{}{ 167 "api-version": APIVersion, 168 } 169 170 preparer := autorest.CreatePreparer( 171 autorest.AsDelete(), 172 autorest.WithBaseURL(client.BaseURI), 173 autorest.WithPathParameters("/Resources/Gateways/{gatewayResourceName}", pathParameters), 174 autorest.WithQueryParameters(queryParameters)) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// DeleteSender sends the Delete request. The method will close the 179// http.Response Body if it receives an error. 180func (client MeshGatewayClient) DeleteSender(req *http.Request) (*http.Response, error) { 181 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 182} 183 184// DeleteResponder handles the response to the Delete request. The method always 185// closes the http.Response Body. 186func (client MeshGatewayClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 187 err = autorest.Respond( 188 resp, 189 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 190 autorest.ByClosing()) 191 result.Response = resp 192 return 193} 194 195// Get gets the information about the Gateway resource with the given name. The information include the description and 196// other properties of the Gateway. 197// Parameters: 198// gatewayResourceName - the identity of the gateway. 199func (client MeshGatewayClient) Get(ctx context.Context, gatewayResourceName string) (result GatewayResourceDescription, err error) { 200 if tracing.IsEnabled() { 201 ctx = tracing.StartSpan(ctx, fqdn+"/MeshGatewayClient.Get") 202 defer func() { 203 sc := -1 204 if result.Response.Response != nil { 205 sc = result.Response.Response.StatusCode 206 } 207 tracing.EndSpan(ctx, sc, err) 208 }() 209 } 210 req, err := client.GetPreparer(ctx, gatewayResourceName) 211 if err != nil { 212 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "Get", nil, "Failure preparing request") 213 return 214 } 215 216 resp, err := client.GetSender(req) 217 if err != nil { 218 result.Response = autorest.Response{Response: resp} 219 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "Get", resp, "Failure sending request") 220 return 221 } 222 223 result, err = client.GetResponder(resp) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "Get", resp, "Failure responding to request") 226 return 227 } 228 229 return 230} 231 232// GetPreparer prepares the Get request. 233func (client MeshGatewayClient) GetPreparer(ctx context.Context, gatewayResourceName string) (*http.Request, error) { 234 pathParameters := map[string]interface{}{ 235 "gatewayResourceName": gatewayResourceName, 236 } 237 238 const APIVersion = "6.4-preview" 239 queryParameters := map[string]interface{}{ 240 "api-version": APIVersion, 241 } 242 243 preparer := autorest.CreatePreparer( 244 autorest.AsGet(), 245 autorest.WithBaseURL(client.BaseURI), 246 autorest.WithPathParameters("/Resources/Gateways/{gatewayResourceName}", pathParameters), 247 autorest.WithQueryParameters(queryParameters)) 248 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 249} 250 251// GetSender sends the Get request. The method will close the 252// http.Response Body if it receives an error. 253func (client MeshGatewayClient) GetSender(req *http.Request) (*http.Response, error) { 254 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 255} 256 257// GetResponder handles the response to the Get request. The method always 258// closes the http.Response Body. 259func (client MeshGatewayClient) GetResponder(resp *http.Response) (result GatewayResourceDescription, err error) { 260 err = autorest.Respond( 261 resp, 262 azure.WithErrorUnlessStatusCode(http.StatusOK), 263 autorest.ByUnmarshallingJSON(&result), 264 autorest.ByClosing()) 265 result.Response = autorest.Response{Response: resp} 266 return 267} 268 269// List gets the information about all gateway resources in a given resource group. The information include the 270// description and other properties of the Gateway. 271func (client MeshGatewayClient) List(ctx context.Context) (result PagedGatewayResourceDescriptionList, err error) { 272 if tracing.IsEnabled() { 273 ctx = tracing.StartSpan(ctx, fqdn+"/MeshGatewayClient.List") 274 defer func() { 275 sc := -1 276 if result.Response.Response != nil { 277 sc = result.Response.Response.StatusCode 278 } 279 tracing.EndSpan(ctx, sc, err) 280 }() 281 } 282 req, err := client.ListPreparer(ctx) 283 if err != nil { 284 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "List", nil, "Failure preparing request") 285 return 286 } 287 288 resp, err := client.ListSender(req) 289 if err != nil { 290 result.Response = autorest.Response{Response: resp} 291 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "List", resp, "Failure sending request") 292 return 293 } 294 295 result, err = client.ListResponder(resp) 296 if err != nil { 297 err = autorest.NewErrorWithError(err, "servicefabric.MeshGatewayClient", "List", resp, "Failure responding to request") 298 return 299 } 300 301 return 302} 303 304// ListPreparer prepares the List request. 305func (client MeshGatewayClient) ListPreparer(ctx context.Context) (*http.Request, error) { 306 const APIVersion = "6.4-preview" 307 queryParameters := map[string]interface{}{ 308 "api-version": APIVersion, 309 } 310 311 preparer := autorest.CreatePreparer( 312 autorest.AsGet(), 313 autorest.WithBaseURL(client.BaseURI), 314 autorest.WithPath("/Resources/Gateways"), 315 autorest.WithQueryParameters(queryParameters)) 316 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 317} 318 319// ListSender sends the List request. The method will close the 320// http.Response Body if it receives an error. 321func (client MeshGatewayClient) ListSender(req *http.Request) (*http.Response, error) { 322 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 323} 324 325// ListResponder handles the response to the List request. The method always 326// closes the http.Response Body. 327func (client MeshGatewayClient) ListResponder(resp *http.Response) (result PagedGatewayResourceDescriptionList, err error) { 328 err = autorest.Respond( 329 resp, 330 azure.WithErrorUnlessStatusCode(http.StatusOK), 331 autorest.ByUnmarshallingJSON(&result), 332 autorest.ByClosing()) 333 result.Response = autorest.Response{Response: resp} 334 return 335} 336