github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_power_panel.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright 2020 The go-netbox Authors.
     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  //
     9  //   http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  //
    17  
    18  package models
    19  
    20  // This file was generated by the swagger tool.
    21  // Editing this file might prove futile when you re-run the swagger generate command
    22  
    23  import (
    24  	"context"
    25  
    26  	"github.com/go-openapi/errors"
    27  	"github.com/go-openapi/strfmt"
    28  	"github.com/go-openapi/swag"
    29  	"github.com/go-openapi/validate"
    30  )
    31  
    32  // NestedPowerPanel nested power panel
    33  //
    34  // swagger:model NestedPowerPanel
    35  type NestedPowerPanel struct {
    36  
    37  	// Display
    38  	// Read Only: true
    39  	Display string `json:"display,omitempty"`
    40  
    41  	// Id
    42  	// Read Only: true
    43  	ID int64 `json:"id,omitempty"`
    44  
    45  	// Name
    46  	// Required: true
    47  	// Max Length: 100
    48  	// Min Length: 1
    49  	Name *string `json:"name"`
    50  
    51  	// Powerfeed count
    52  	// Read Only: true
    53  	PowerfeedCount int64 `json:"powerfeed_count,omitempty"`
    54  
    55  	// Url
    56  	// Read Only: true
    57  	// Format: uri
    58  	URL strfmt.URI `json:"url,omitempty"`
    59  }
    60  
    61  // Validate validates this nested power panel
    62  func (m *NestedPowerPanel) Validate(formats strfmt.Registry) error {
    63  	var res []error
    64  
    65  	if err := m.validateName(formats); err != nil {
    66  		res = append(res, err)
    67  	}
    68  
    69  	if err := m.validateURL(formats); err != nil {
    70  		res = append(res, err)
    71  	}
    72  
    73  	if len(res) > 0 {
    74  		return errors.CompositeValidationError(res...)
    75  	}
    76  	return nil
    77  }
    78  
    79  func (m *NestedPowerPanel) validateName(formats strfmt.Registry) error {
    80  
    81  	if err := validate.Required("name", "body", m.Name); err != nil {
    82  		return err
    83  	}
    84  
    85  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
    86  		return err
    87  	}
    88  
    89  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
    90  		return err
    91  	}
    92  
    93  	return nil
    94  }
    95  
    96  func (m *NestedPowerPanel) validateURL(formats strfmt.Registry) error {
    97  	if swag.IsZero(m.URL) { // not required
    98  		return nil
    99  	}
   100  
   101  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   102  		return err
   103  	}
   104  
   105  	return nil
   106  }
   107  
   108  // ContextValidate validate this nested power panel based on the context it is used
   109  func (m *NestedPowerPanel) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   110  	var res []error
   111  
   112  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   113  		res = append(res, err)
   114  	}
   115  
   116  	if err := m.contextValidateID(ctx, formats); err != nil {
   117  		res = append(res, err)
   118  	}
   119  
   120  	if err := m.contextValidatePowerfeedCount(ctx, formats); err != nil {
   121  		res = append(res, err)
   122  	}
   123  
   124  	if err := m.contextValidateURL(ctx, formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	if len(res) > 0 {
   129  		return errors.CompositeValidationError(res...)
   130  	}
   131  	return nil
   132  }
   133  
   134  func (m *NestedPowerPanel) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   135  
   136  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   137  		return err
   138  	}
   139  
   140  	return nil
   141  }
   142  
   143  func (m *NestedPowerPanel) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   144  
   145  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   146  		return err
   147  	}
   148  
   149  	return nil
   150  }
   151  
   152  func (m *NestedPowerPanel) contextValidatePowerfeedCount(ctx context.Context, formats strfmt.Registry) error {
   153  
   154  	if err := validate.ReadOnly(ctx, "powerfeed_count", "body", int64(m.PowerfeedCount)); err != nil {
   155  		return err
   156  	}
   157  
   158  	return nil
   159  }
   160  
   161  func (m *NestedPowerPanel) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   162  
   163  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   164  		return err
   165  	}
   166  
   167  	return nil
   168  }
   169  
   170  // MarshalBinary interface implementation
   171  func (m *NestedPowerPanel) MarshalBinary() ([]byte, error) {
   172  	if m == nil {
   173  		return nil, nil
   174  	}
   175  	return swag.WriteJSON(m)
   176  }
   177  
   178  // UnmarshalBinary interface implementation
   179  func (m *NestedPowerPanel) UnmarshalBinary(b []byte) error {
   180  	var res NestedPowerPanel
   181  	if err := swag.ReadJSON(b, &res); err != nil {
   182  		return err
   183  	}
   184  	*m = res
   185  	return nil
   186  }