...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-09-01/links/models.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-09-01/links

     1  package links
     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  	"encoding/json"
    12  	"github.com/Azure/go-autorest/autorest"
    13  	"github.com/Azure/go-autorest/autorest/to"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // The package's fully qualified name.
    19  const fqdn = "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-09-01/links"
    20  
    21  // Operation microsoft.Resources operation
    22  type Operation struct {
    23  	// Name - Operation name: {provider}/{resource}/{operation}
    24  	Name *string `json:"name,omitempty"`
    25  	// Display - The object that represents the operation.
    26  	Display *OperationDisplay `json:"display,omitempty"`
    27  }
    28  
    29  // OperationDisplay the object that represents the operation.
    30  type OperationDisplay struct {
    31  	// Provider - Service provider: Microsoft.Resources
    32  	Provider *string `json:"provider,omitempty"`
    33  	// Resource - Resource on which the operation is performed: Profile, endpoint, etc.
    34  	Resource *string `json:"resource,omitempty"`
    35  	// Operation - Operation type: Read, write, delete, etc.
    36  	Operation *string `json:"operation,omitempty"`
    37  	// Description - Description of the operation.
    38  	Description *string `json:"description,omitempty"`
    39  }
    40  
    41  // OperationListResult result of the request to list Microsoft.Resources operations. It contains a list of
    42  // operations and a URL link to get the next set of results.
    43  type OperationListResult struct {
    44  	autorest.Response `json:"-"`
    45  	// Value - List of Microsoft.Resources operations.
    46  	Value *[]Operation `json:"value,omitempty"`
    47  	// NextLink - URL to get the next set of operation list results if there are any.
    48  	NextLink *string `json:"nextLink,omitempty"`
    49  }
    50  
    51  // OperationListResultIterator provides access to a complete listing of Operation values.
    52  type OperationListResultIterator struct {
    53  	i    int
    54  	page OperationListResultPage
    55  }
    56  
    57  // NextWithContext advances to the next value.  If there was an error making
    58  // the request the iterator does not advance and the error is returned.
    59  func (iter *OperationListResultIterator) NextWithContext(ctx context.Context) (err error) {
    60  	if tracing.IsEnabled() {
    61  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultIterator.NextWithContext")
    62  		defer func() {
    63  			sc := -1
    64  			if iter.Response().Response.Response != nil {
    65  				sc = iter.Response().Response.Response.StatusCode
    66  			}
    67  			tracing.EndSpan(ctx, sc, err)
    68  		}()
    69  	}
    70  	iter.i++
    71  	if iter.i < len(iter.page.Values()) {
    72  		return nil
    73  	}
    74  	err = iter.page.NextWithContext(ctx)
    75  	if err != nil {
    76  		iter.i--
    77  		return err
    78  	}
    79  	iter.i = 0
    80  	return nil
    81  }
    82  
    83  // Next advances to the next value.  If there was an error making
    84  // the request the iterator does not advance and the error is returned.
    85  // Deprecated: Use NextWithContext() instead.
    86  func (iter *OperationListResultIterator) Next() error {
    87  	return iter.NextWithContext(context.Background())
    88  }
    89  
    90  // NotDone returns true if the enumeration should be started or is not yet complete.
    91  func (iter OperationListResultIterator) NotDone() bool {
    92  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
    93  }
    94  
    95  // Response returns the raw server response from the last page request.
    96  func (iter OperationListResultIterator) Response() OperationListResult {
    97  	return iter.page.Response()
    98  }
    99  
   100  // Value returns the current value or a zero-initialized value if the
   101  // iterator has advanced beyond the end of the collection.
   102  func (iter OperationListResultIterator) Value() Operation {
   103  	if !iter.page.NotDone() {
   104  		return Operation{}
   105  	}
   106  	return iter.page.Values()[iter.i]
   107  }
   108  
   109  // Creates a new instance of the OperationListResultIterator type.
   110  func NewOperationListResultIterator(page OperationListResultPage) OperationListResultIterator {
   111  	return OperationListResultIterator{page: page}
   112  }
   113  
   114  // IsEmpty returns true if the ListResult contains no values.
   115  func (olr OperationListResult) IsEmpty() bool {
   116  	return olr.Value == nil || len(*olr.Value) == 0
   117  }
   118  
   119  // hasNextLink returns true if the NextLink is not empty.
   120  func (olr OperationListResult) hasNextLink() bool {
   121  	return olr.NextLink != nil && len(*olr.NextLink) != 0
   122  }
   123  
   124  // operationListResultPreparer prepares a request to retrieve the next set of results.
   125  // It returns nil if no more results exist.
   126  func (olr OperationListResult) operationListResultPreparer(ctx context.Context) (*http.Request, error) {
   127  	if !olr.hasNextLink() {
   128  		return nil, nil
   129  	}
   130  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   131  		autorest.AsJSON(),
   132  		autorest.AsGet(),
   133  		autorest.WithBaseURL(to.String(olr.NextLink)))
   134  }
   135  
   136  // OperationListResultPage contains a page of Operation values.
   137  type OperationListResultPage struct {
   138  	fn  func(context.Context, OperationListResult) (OperationListResult, error)
   139  	olr OperationListResult
   140  }
   141  
   142  // NextWithContext advances to the next page of values.  If there was an error making
   143  // the request the page does not advance and the error is returned.
   144  func (page *OperationListResultPage) NextWithContext(ctx context.Context) (err error) {
   145  	if tracing.IsEnabled() {
   146  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultPage.NextWithContext")
   147  		defer func() {
   148  			sc := -1
   149  			if page.Response().Response.Response != nil {
   150  				sc = page.Response().Response.Response.StatusCode
   151  			}
   152  			tracing.EndSpan(ctx, sc, err)
   153  		}()
   154  	}
   155  	for {
   156  		next, err := page.fn(ctx, page.olr)
   157  		if err != nil {
   158  			return err
   159  		}
   160  		page.olr = next
   161  		if !next.hasNextLink() || !next.IsEmpty() {
   162  			break
   163  		}
   164  	}
   165  	return nil
   166  }
   167  
   168  // Next advances to the next page of values.  If there was an error making
   169  // the request the page does not advance and the error is returned.
   170  // Deprecated: Use NextWithContext() instead.
   171  func (page *OperationListResultPage) Next() error {
   172  	return page.NextWithContext(context.Background())
   173  }
   174  
   175  // NotDone returns true if the page enumeration should be started or is not yet complete.
   176  func (page OperationListResultPage) NotDone() bool {
   177  	return !page.olr.IsEmpty()
   178  }
   179  
   180  // Response returns the raw server response from the last page request.
   181  func (page OperationListResultPage) Response() OperationListResult {
   182  	return page.olr
   183  }
   184  
   185  // Values returns the slice of values for the current page or nil if there are no values.
   186  func (page OperationListResultPage) Values() []Operation {
   187  	if page.olr.IsEmpty() {
   188  		return nil
   189  	}
   190  	return *page.olr.Value
   191  }
   192  
   193  // Creates a new instance of the OperationListResultPage type.
   194  func NewOperationListResultPage(cur OperationListResult, getNextPage func(context.Context, OperationListResult) (OperationListResult, error)) OperationListResultPage {
   195  	return OperationListResultPage{
   196  		fn:  getNextPage,
   197  		olr: cur,
   198  	}
   199  }
   200  
   201  // ResourceLink the resource link.
   202  type ResourceLink struct {
   203  	autorest.Response `json:"-"`
   204  	// ID - READ-ONLY; The fully qualified ID of the resource link.
   205  	ID *string `json:"id,omitempty"`
   206  	// Name - READ-ONLY; The name of the resource link.
   207  	Name *string `json:"name,omitempty"`
   208  	// Type - READ-ONLY; The resource link object.
   209  	Type interface{} `json:"type,omitempty"`
   210  	// Properties - Properties for resource link.
   211  	Properties *ResourceLinkProperties `json:"properties,omitempty"`
   212  }
   213  
   214  // MarshalJSON is the custom marshaler for ResourceLink.
   215  func (rl ResourceLink) MarshalJSON() ([]byte, error) {
   216  	objectMap := make(map[string]interface{})
   217  	if rl.Properties != nil {
   218  		objectMap["properties"] = rl.Properties
   219  	}
   220  	return json.Marshal(objectMap)
   221  }
   222  
   223  // ResourceLinkFilter resource link filter.
   224  type ResourceLinkFilter struct {
   225  	// TargetID - The ID of the target resource.
   226  	TargetID *string `json:"targetId,omitempty"`
   227  }
   228  
   229  // ResourceLinkProperties the resource link properties.
   230  type ResourceLinkProperties struct {
   231  	// SourceID - READ-ONLY; The fully qualified ID of the source resource in the link.
   232  	SourceID *string `json:"sourceId,omitempty"`
   233  	// TargetID - The fully qualified ID of the target resource in the link.
   234  	TargetID *string `json:"targetId,omitempty"`
   235  	// Notes - Notes about the resource link.
   236  	Notes *string `json:"notes,omitempty"`
   237  }
   238  
   239  // MarshalJSON is the custom marshaler for ResourceLinkProperties.
   240  func (rlp ResourceLinkProperties) MarshalJSON() ([]byte, error) {
   241  	objectMap := make(map[string]interface{})
   242  	if rlp.TargetID != nil {
   243  		objectMap["targetId"] = rlp.TargetID
   244  	}
   245  	if rlp.Notes != nil {
   246  		objectMap["notes"] = rlp.Notes
   247  	}
   248  	return json.Marshal(objectMap)
   249  }
   250  
   251  // ResourceLinkResult list of resource links.
   252  type ResourceLinkResult struct {
   253  	autorest.Response `json:"-"`
   254  	// Value - An array of resource links.
   255  	Value *[]ResourceLink `json:"value,omitempty"`
   256  	// NextLink - READ-ONLY; The URL to use for getting the next set of results.
   257  	NextLink *string `json:"nextLink,omitempty"`
   258  }
   259  
   260  // MarshalJSON is the custom marshaler for ResourceLinkResult.
   261  func (rlr ResourceLinkResult) MarshalJSON() ([]byte, error) {
   262  	objectMap := make(map[string]interface{})
   263  	if rlr.Value != nil {
   264  		objectMap["value"] = rlr.Value
   265  	}
   266  	return json.Marshal(objectMap)
   267  }
   268  
   269  // ResourceLinkResultIterator provides access to a complete listing of ResourceLink values.
   270  type ResourceLinkResultIterator struct {
   271  	i    int
   272  	page ResourceLinkResultPage
   273  }
   274  
   275  // NextWithContext advances to the next value.  If there was an error making
   276  // the request the iterator does not advance and the error is returned.
   277  func (iter *ResourceLinkResultIterator) NextWithContext(ctx context.Context) (err error) {
   278  	if tracing.IsEnabled() {
   279  		ctx = tracing.StartSpan(ctx, fqdn+"/ResourceLinkResultIterator.NextWithContext")
   280  		defer func() {
   281  			sc := -1
   282  			if iter.Response().Response.Response != nil {
   283  				sc = iter.Response().Response.Response.StatusCode
   284  			}
   285  			tracing.EndSpan(ctx, sc, err)
   286  		}()
   287  	}
   288  	iter.i++
   289  	if iter.i < len(iter.page.Values()) {
   290  		return nil
   291  	}
   292  	err = iter.page.NextWithContext(ctx)
   293  	if err != nil {
   294  		iter.i--
   295  		return err
   296  	}
   297  	iter.i = 0
   298  	return nil
   299  }
   300  
   301  // Next advances to the next value.  If there was an error making
   302  // the request the iterator does not advance and the error is returned.
   303  // Deprecated: Use NextWithContext() instead.
   304  func (iter *ResourceLinkResultIterator) Next() error {
   305  	return iter.NextWithContext(context.Background())
   306  }
   307  
   308  // NotDone returns true if the enumeration should be started or is not yet complete.
   309  func (iter ResourceLinkResultIterator) NotDone() bool {
   310  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   311  }
   312  
   313  // Response returns the raw server response from the last page request.
   314  func (iter ResourceLinkResultIterator) Response() ResourceLinkResult {
   315  	return iter.page.Response()
   316  }
   317  
   318  // Value returns the current value or a zero-initialized value if the
   319  // iterator has advanced beyond the end of the collection.
   320  func (iter ResourceLinkResultIterator) Value() ResourceLink {
   321  	if !iter.page.NotDone() {
   322  		return ResourceLink{}
   323  	}
   324  	return iter.page.Values()[iter.i]
   325  }
   326  
   327  // Creates a new instance of the ResourceLinkResultIterator type.
   328  func NewResourceLinkResultIterator(page ResourceLinkResultPage) ResourceLinkResultIterator {
   329  	return ResourceLinkResultIterator{page: page}
   330  }
   331  
   332  // IsEmpty returns true if the ListResult contains no values.
   333  func (rlr ResourceLinkResult) IsEmpty() bool {
   334  	return rlr.Value == nil || len(*rlr.Value) == 0
   335  }
   336  
   337  // hasNextLink returns true if the NextLink is not empty.
   338  func (rlr ResourceLinkResult) hasNextLink() bool {
   339  	return rlr.NextLink != nil && len(*rlr.NextLink) != 0
   340  }
   341  
   342  // resourceLinkResultPreparer prepares a request to retrieve the next set of results.
   343  // It returns nil if no more results exist.
   344  func (rlr ResourceLinkResult) resourceLinkResultPreparer(ctx context.Context) (*http.Request, error) {
   345  	if !rlr.hasNextLink() {
   346  		return nil, nil
   347  	}
   348  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   349  		autorest.AsJSON(),
   350  		autorest.AsGet(),
   351  		autorest.WithBaseURL(to.String(rlr.NextLink)))
   352  }
   353  
   354  // ResourceLinkResultPage contains a page of ResourceLink values.
   355  type ResourceLinkResultPage struct {
   356  	fn  func(context.Context, ResourceLinkResult) (ResourceLinkResult, error)
   357  	rlr ResourceLinkResult
   358  }
   359  
   360  // NextWithContext advances to the next page of values.  If there was an error making
   361  // the request the page does not advance and the error is returned.
   362  func (page *ResourceLinkResultPage) NextWithContext(ctx context.Context) (err error) {
   363  	if tracing.IsEnabled() {
   364  		ctx = tracing.StartSpan(ctx, fqdn+"/ResourceLinkResultPage.NextWithContext")
   365  		defer func() {
   366  			sc := -1
   367  			if page.Response().Response.Response != nil {
   368  				sc = page.Response().Response.Response.StatusCode
   369  			}
   370  			tracing.EndSpan(ctx, sc, err)
   371  		}()
   372  	}
   373  	for {
   374  		next, err := page.fn(ctx, page.rlr)
   375  		if err != nil {
   376  			return err
   377  		}
   378  		page.rlr = next
   379  		if !next.hasNextLink() || !next.IsEmpty() {
   380  			break
   381  		}
   382  	}
   383  	return nil
   384  }
   385  
   386  // Next advances to the next page of values.  If there was an error making
   387  // the request the page does not advance and the error is returned.
   388  // Deprecated: Use NextWithContext() instead.
   389  func (page *ResourceLinkResultPage) Next() error {
   390  	return page.NextWithContext(context.Background())
   391  }
   392  
   393  // NotDone returns true if the page enumeration should be started or is not yet complete.
   394  func (page ResourceLinkResultPage) NotDone() bool {
   395  	return !page.rlr.IsEmpty()
   396  }
   397  
   398  // Response returns the raw server response from the last page request.
   399  func (page ResourceLinkResultPage) Response() ResourceLinkResult {
   400  	return page.rlr
   401  }
   402  
   403  // Values returns the slice of values for the current page or nil if there are no values.
   404  func (page ResourceLinkResultPage) Values() []ResourceLink {
   405  	if page.rlr.IsEmpty() {
   406  		return nil
   407  	}
   408  	return *page.rlr.Value
   409  }
   410  
   411  // Creates a new instance of the ResourceLinkResultPage type.
   412  func NewResourceLinkResultPage(cur ResourceLinkResult, getNextPage func(context.Context, ResourceLinkResult) (ResourceLinkResult, error)) ResourceLinkResultPage {
   413  	return ResourceLinkResultPage{
   414  		fn:  getNextPage,
   415  		rlr: cur,
   416  	}
   417  }
   418  

View as plain text