...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2015-01-01/locks/models.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2015-01-01/locks

     1  package locks
     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/2015-01-01/locks"
    20  
    21  // ManagementLockListResult list of management locks.
    22  type ManagementLockListResult struct {
    23  	autorest.Response `json:"-"`
    24  	// Value - The list of locks.
    25  	Value *[]ManagementLockObject `json:"value,omitempty"`
    26  	// NextLink - The URL to get the next set of results.
    27  	NextLink *string `json:"nextLink,omitempty"`
    28  }
    29  
    30  // ManagementLockListResultIterator provides access to a complete listing of ManagementLockObject values.
    31  type ManagementLockListResultIterator struct {
    32  	i    int
    33  	page ManagementLockListResultPage
    34  }
    35  
    36  // NextWithContext advances to the next value.  If there was an error making
    37  // the request the iterator does not advance and the error is returned.
    38  func (iter *ManagementLockListResultIterator) NextWithContext(ctx context.Context) (err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementLockListResultIterator.NextWithContext")
    41  		defer func() {
    42  			sc := -1
    43  			if iter.Response().Response.Response != nil {
    44  				sc = iter.Response().Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	iter.i++
    50  	if iter.i < len(iter.page.Values()) {
    51  		return nil
    52  	}
    53  	err = iter.page.NextWithContext(ctx)
    54  	if err != nil {
    55  		iter.i--
    56  		return err
    57  	}
    58  	iter.i = 0
    59  	return nil
    60  }
    61  
    62  // Next advances to the next value.  If there was an error making
    63  // the request the iterator does not advance and the error is returned.
    64  // Deprecated: Use NextWithContext() instead.
    65  func (iter *ManagementLockListResultIterator) Next() error {
    66  	return iter.NextWithContext(context.Background())
    67  }
    68  
    69  // NotDone returns true if the enumeration should be started or is not yet complete.
    70  func (iter ManagementLockListResultIterator) NotDone() bool {
    71  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
    72  }
    73  
    74  // Response returns the raw server response from the last page request.
    75  func (iter ManagementLockListResultIterator) Response() ManagementLockListResult {
    76  	return iter.page.Response()
    77  }
    78  
    79  // Value returns the current value or a zero-initialized value if the
    80  // iterator has advanced beyond the end of the collection.
    81  func (iter ManagementLockListResultIterator) Value() ManagementLockObject {
    82  	if !iter.page.NotDone() {
    83  		return ManagementLockObject{}
    84  	}
    85  	return iter.page.Values()[iter.i]
    86  }
    87  
    88  // Creates a new instance of the ManagementLockListResultIterator type.
    89  func NewManagementLockListResultIterator(page ManagementLockListResultPage) ManagementLockListResultIterator {
    90  	return ManagementLockListResultIterator{page: page}
    91  }
    92  
    93  // IsEmpty returns true if the ListResult contains no values.
    94  func (mllr ManagementLockListResult) IsEmpty() bool {
    95  	return mllr.Value == nil || len(*mllr.Value) == 0
    96  }
    97  
    98  // hasNextLink returns true if the NextLink is not empty.
    99  func (mllr ManagementLockListResult) hasNextLink() bool {
   100  	return mllr.NextLink != nil && len(*mllr.NextLink) != 0
   101  }
   102  
   103  // managementLockListResultPreparer prepares a request to retrieve the next set of results.
   104  // It returns nil if no more results exist.
   105  func (mllr ManagementLockListResult) managementLockListResultPreparer(ctx context.Context) (*http.Request, error) {
   106  	if !mllr.hasNextLink() {
   107  		return nil, nil
   108  	}
   109  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   110  		autorest.AsJSON(),
   111  		autorest.AsGet(),
   112  		autorest.WithBaseURL(to.String(mllr.NextLink)))
   113  }
   114  
   115  // ManagementLockListResultPage contains a page of ManagementLockObject values.
   116  type ManagementLockListResultPage struct {
   117  	fn   func(context.Context, ManagementLockListResult) (ManagementLockListResult, error)
   118  	mllr ManagementLockListResult
   119  }
   120  
   121  // NextWithContext advances to the next page of values.  If there was an error making
   122  // the request the page does not advance and the error is returned.
   123  func (page *ManagementLockListResultPage) NextWithContext(ctx context.Context) (err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementLockListResultPage.NextWithContext")
   126  		defer func() {
   127  			sc := -1
   128  			if page.Response().Response.Response != nil {
   129  				sc = page.Response().Response.Response.StatusCode
   130  			}
   131  			tracing.EndSpan(ctx, sc, err)
   132  		}()
   133  	}
   134  	for {
   135  		next, err := page.fn(ctx, page.mllr)
   136  		if err != nil {
   137  			return err
   138  		}
   139  		page.mllr = next
   140  		if !next.hasNextLink() || !next.IsEmpty() {
   141  			break
   142  		}
   143  	}
   144  	return nil
   145  }
   146  
   147  // Next advances to the next page of values.  If there was an error making
   148  // the request the page does not advance and the error is returned.
   149  // Deprecated: Use NextWithContext() instead.
   150  func (page *ManagementLockListResultPage) Next() error {
   151  	return page.NextWithContext(context.Background())
   152  }
   153  
   154  // NotDone returns true if the page enumeration should be started or is not yet complete.
   155  func (page ManagementLockListResultPage) NotDone() bool {
   156  	return !page.mllr.IsEmpty()
   157  }
   158  
   159  // Response returns the raw server response from the last page request.
   160  func (page ManagementLockListResultPage) Response() ManagementLockListResult {
   161  	return page.mllr
   162  }
   163  
   164  // Values returns the slice of values for the current page or nil if there are no values.
   165  func (page ManagementLockListResultPage) Values() []ManagementLockObject {
   166  	if page.mllr.IsEmpty() {
   167  		return nil
   168  	}
   169  	return *page.mllr.Value
   170  }
   171  
   172  // Creates a new instance of the ManagementLockListResultPage type.
   173  func NewManagementLockListResultPage(cur ManagementLockListResult, getNextPage func(context.Context, ManagementLockListResult) (ManagementLockListResult, error)) ManagementLockListResultPage {
   174  	return ManagementLockListResultPage{
   175  		fn:   getNextPage,
   176  		mllr: cur,
   177  	}
   178  }
   179  
   180  // ManagementLockObject management lock information.
   181  type ManagementLockObject struct {
   182  	autorest.Response `json:"-"`
   183  	// ManagementLockProperties - The properties of the lock.
   184  	*ManagementLockProperties `json:"properties,omitempty"`
   185  	// ID - READ-ONLY; The Id of the lock.
   186  	ID *string `json:"id,omitempty"`
   187  	// Type - READ-ONLY; The type of the lock.
   188  	Type *string `json:"type,omitempty"`
   189  	// Name - The name of the lock.
   190  	Name *string `json:"name,omitempty"`
   191  }
   192  
   193  // MarshalJSON is the custom marshaler for ManagementLockObject.
   194  func (mlo ManagementLockObject) MarshalJSON() ([]byte, error) {
   195  	objectMap := make(map[string]interface{})
   196  	if mlo.ManagementLockProperties != nil {
   197  		objectMap["properties"] = mlo.ManagementLockProperties
   198  	}
   199  	if mlo.Name != nil {
   200  		objectMap["name"] = mlo.Name
   201  	}
   202  	return json.Marshal(objectMap)
   203  }
   204  
   205  // UnmarshalJSON is the custom unmarshaler for ManagementLockObject struct.
   206  func (mlo *ManagementLockObject) UnmarshalJSON(body []byte) error {
   207  	var m map[string]*json.RawMessage
   208  	err := json.Unmarshal(body, &m)
   209  	if err != nil {
   210  		return err
   211  	}
   212  	for k, v := range m {
   213  		switch k {
   214  		case "properties":
   215  			if v != nil {
   216  				var managementLockProperties ManagementLockProperties
   217  				err = json.Unmarshal(*v, &managementLockProperties)
   218  				if err != nil {
   219  					return err
   220  				}
   221  				mlo.ManagementLockProperties = &managementLockProperties
   222  			}
   223  		case "id":
   224  			if v != nil {
   225  				var ID string
   226  				err = json.Unmarshal(*v, &ID)
   227  				if err != nil {
   228  					return err
   229  				}
   230  				mlo.ID = &ID
   231  			}
   232  		case "type":
   233  			if v != nil {
   234  				var typeVar string
   235  				err = json.Unmarshal(*v, &typeVar)
   236  				if err != nil {
   237  					return err
   238  				}
   239  				mlo.Type = &typeVar
   240  			}
   241  		case "name":
   242  			if v != nil {
   243  				var name string
   244  				err = json.Unmarshal(*v, &name)
   245  				if err != nil {
   246  					return err
   247  				}
   248  				mlo.Name = &name
   249  			}
   250  		}
   251  	}
   252  
   253  	return nil
   254  }
   255  
   256  // ManagementLockProperties the management lock properties.
   257  type ManagementLockProperties struct {
   258  	// Level - The lock level of the management lock. Possible values include: 'NotSpecified', 'CanNotDelete', 'ReadOnly'
   259  	Level LockLevel `json:"level,omitempty"`
   260  	// Notes - The notes of the management lock.
   261  	Notes *string `json:"notes,omitempty"`
   262  }
   263  

View as plain text