1package eventgrid 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/tracing" 25 "net/http" 26) 27 28// TopicTypesClient is the azure EventGrid Management Client 29type TopicTypesClient struct { 30 BaseClient 31} 32 33// NewTopicTypesClient creates an instance of the TopicTypesClient client. 34func NewTopicTypesClient(subscriptionID string) TopicTypesClient { 35 return NewTopicTypesClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewTopicTypesClientWithBaseURI creates an instance of the TopicTypesClient client using a custom endpoint. Use this 39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewTopicTypesClientWithBaseURI(baseURI string, subscriptionID string) TopicTypesClient { 41 return TopicTypesClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// Get get information about a topic type 45// Parameters: 46// topicTypeName - name of the topic type 47func (client TopicTypesClient) Get(ctx context.Context, topicTypeName string) (result TopicTypeInfo, err error) { 48 if tracing.IsEnabled() { 49 ctx = tracing.StartSpan(ctx, fqdn+"/TopicTypesClient.Get") 50 defer func() { 51 sc := -1 52 if result.Response.Response != nil { 53 sc = result.Response.Response.StatusCode 54 } 55 tracing.EndSpan(ctx, sc, err) 56 }() 57 } 58 req, err := client.GetPreparer(ctx, topicTypeName) 59 if err != nil { 60 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "Get", nil, "Failure preparing request") 61 return 62 } 63 64 resp, err := client.GetSender(req) 65 if err != nil { 66 result.Response = autorest.Response{Response: resp} 67 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "Get", resp, "Failure sending request") 68 return 69 } 70 71 result, err = client.GetResponder(resp) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "Get", resp, "Failure responding to request") 74 } 75 76 return 77} 78 79// GetPreparer prepares the Get request. 80func (client TopicTypesClient) GetPreparer(ctx context.Context, topicTypeName string) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "topicTypeName": autorest.Encode("path", topicTypeName), 83 } 84 85 const APIVersion = "2018-05-01-preview" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 90 preparer := autorest.CreatePreparer( 91 autorest.AsGet(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/providers/Microsoft.EventGrid/topicTypes/{topicTypeName}", pathParameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// GetSender sends the Get request. The method will close the 99// http.Response Body if it receives an error. 100func (client TopicTypesClient) GetSender(req *http.Request) (*http.Response, error) { 101 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 102} 103 104// GetResponder handles the response to the Get request. The method always 105// closes the http.Response Body. 106func (client TopicTypesClient) GetResponder(resp *http.Response) (result TopicTypeInfo, err error) { 107 err = autorest.Respond( 108 resp, 109 client.ByInspecting(), 110 azure.WithErrorUnlessStatusCode(http.StatusOK), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116 117// List list all registered topic types 118func (client TopicTypesClient) List(ctx context.Context) (result TopicTypesListResult, err error) { 119 if tracing.IsEnabled() { 120 ctx = tracing.StartSpan(ctx, fqdn+"/TopicTypesClient.List") 121 defer func() { 122 sc := -1 123 if result.Response.Response != nil { 124 sc = result.Response.Response.StatusCode 125 } 126 tracing.EndSpan(ctx, sc, err) 127 }() 128 } 129 req, err := client.ListPreparer(ctx) 130 if err != nil { 131 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "List", nil, "Failure preparing request") 132 return 133 } 134 135 resp, err := client.ListSender(req) 136 if err != nil { 137 result.Response = autorest.Response{Response: resp} 138 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "List", resp, "Failure sending request") 139 return 140 } 141 142 result, err = client.ListResponder(resp) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "List", resp, "Failure responding to request") 145 } 146 147 return 148} 149 150// ListPreparer prepares the List request. 151func (client TopicTypesClient) ListPreparer(ctx context.Context) (*http.Request, error) { 152 const APIVersion = "2018-05-01-preview" 153 queryParameters := map[string]interface{}{ 154 "api-version": APIVersion, 155 } 156 157 preparer := autorest.CreatePreparer( 158 autorest.AsGet(), 159 autorest.WithBaseURL(client.BaseURI), 160 autorest.WithPath("/providers/Microsoft.EventGrid/topicTypes"), 161 autorest.WithQueryParameters(queryParameters)) 162 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 163} 164 165// ListSender sends the List request. The method will close the 166// http.Response Body if it receives an error. 167func (client TopicTypesClient) ListSender(req *http.Request) (*http.Response, error) { 168 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 169} 170 171// ListResponder handles the response to the List request. The method always 172// closes the http.Response Body. 173func (client TopicTypesClient) ListResponder(resp *http.Response) (result TopicTypesListResult, err error) { 174 err = autorest.Respond( 175 resp, 176 client.ByInspecting(), 177 azure.WithErrorUnlessStatusCode(http.StatusOK), 178 autorest.ByUnmarshallingJSON(&result), 179 autorest.ByClosing()) 180 result.Response = autorest.Response{Response: resp} 181 return 182} 183 184// ListEventTypes list event types for a topic type 185// Parameters: 186// topicTypeName - name of the topic type 187func (client TopicTypesClient) ListEventTypes(ctx context.Context, topicTypeName string) (result EventTypesListResult, err error) { 188 if tracing.IsEnabled() { 189 ctx = tracing.StartSpan(ctx, fqdn+"/TopicTypesClient.ListEventTypes") 190 defer func() { 191 sc := -1 192 if result.Response.Response != nil { 193 sc = result.Response.Response.StatusCode 194 } 195 tracing.EndSpan(ctx, sc, err) 196 }() 197 } 198 req, err := client.ListEventTypesPreparer(ctx, topicTypeName) 199 if err != nil { 200 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "ListEventTypes", nil, "Failure preparing request") 201 return 202 } 203 204 resp, err := client.ListEventTypesSender(req) 205 if err != nil { 206 result.Response = autorest.Response{Response: resp} 207 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "ListEventTypes", resp, "Failure sending request") 208 return 209 } 210 211 result, err = client.ListEventTypesResponder(resp) 212 if err != nil { 213 err = autorest.NewErrorWithError(err, "eventgrid.TopicTypesClient", "ListEventTypes", resp, "Failure responding to request") 214 } 215 216 return 217} 218 219// ListEventTypesPreparer prepares the ListEventTypes request. 220func (client TopicTypesClient) ListEventTypesPreparer(ctx context.Context, topicTypeName string) (*http.Request, error) { 221 pathParameters := map[string]interface{}{ 222 "topicTypeName": autorest.Encode("path", topicTypeName), 223 } 224 225 const APIVersion = "2018-05-01-preview" 226 queryParameters := map[string]interface{}{ 227 "api-version": APIVersion, 228 } 229 230 preparer := autorest.CreatePreparer( 231 autorest.AsGet(), 232 autorest.WithBaseURL(client.BaseURI), 233 autorest.WithPathParameters("/providers/Microsoft.EventGrid/topicTypes/{topicTypeName}/eventTypes", pathParameters), 234 autorest.WithQueryParameters(queryParameters)) 235 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 236} 237 238// ListEventTypesSender sends the ListEventTypes request. The method will close the 239// http.Response Body if it receives an error. 240func (client TopicTypesClient) ListEventTypesSender(req *http.Request) (*http.Response, error) { 241 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 242} 243 244// ListEventTypesResponder handles the response to the ListEventTypes request. The method always 245// closes the http.Response Body. 246func (client TopicTypesClient) ListEventTypesResponder(resp *http.Response) (result EventTypesListResult, err error) { 247 err = autorest.Respond( 248 resp, 249 client.ByInspecting(), 250 azure.WithErrorUnlessStatusCode(http.StatusOK), 251 autorest.ByUnmarshallingJSON(&result), 252 autorest.ByClosing()) 253 result.Response = autorest.Response{Response: resp} 254 return 255} 256