github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-log-service/preview/2021-03-30/models/runtime_error.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package models
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"context"
    10  	"strconv"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/strfmt"
    14  	"github.com/go-openapi/swag"
    15  )
    16  
    17  // RuntimeError runtime error
    18  //
    19  // swagger:model runtimeError
    20  type RuntimeError struct {
    21  
    22  	// code
    23  	Code int32 `json:"code,omitempty"`
    24  
    25  	// details
    26  	Details []*ProtobufAny `json:"details"`
    27  
    28  	// error
    29  	Error string `json:"error,omitempty"`
    30  
    31  	// message
    32  	Message string `json:"message,omitempty"`
    33  }
    34  
    35  // Validate validates this runtime error
    36  func (m *RuntimeError) Validate(formats strfmt.Registry) error {
    37  	var res []error
    38  
    39  	if err := m.validateDetails(formats); err != nil {
    40  		res = append(res, err)
    41  	}
    42  
    43  	if len(res) > 0 {
    44  		return errors.CompositeValidationError(res...)
    45  	}
    46  	return nil
    47  }
    48  
    49  func (m *RuntimeError) validateDetails(formats strfmt.Registry) error {
    50  	if swag.IsZero(m.Details) { // not required
    51  		return nil
    52  	}
    53  
    54  	for i := 0; i < len(m.Details); i++ {
    55  		if swag.IsZero(m.Details[i]) { // not required
    56  			continue
    57  		}
    58  
    59  		if m.Details[i] != nil {
    60  			if err := m.Details[i].Validate(formats); err != nil {
    61  				if ve, ok := err.(*errors.Validation); ok {
    62  					return ve.ValidateName("details" + "." + strconv.Itoa(i))
    63  				} else if ce, ok := err.(*errors.CompositeError); ok {
    64  					return ce.ValidateName("details" + "." + strconv.Itoa(i))
    65  				}
    66  				return err
    67  			}
    68  		}
    69  
    70  	}
    71  
    72  	return nil
    73  }
    74  
    75  // ContextValidate validate this runtime error based on the context it is used
    76  func (m *RuntimeError) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.contextValidateDetails(ctx, formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if len(res) > 0 {
    84  		return errors.CompositeValidationError(res...)
    85  	}
    86  	return nil
    87  }
    88  
    89  func (m *RuntimeError) contextValidateDetails(ctx context.Context, formats strfmt.Registry) error {
    90  
    91  	for i := 0; i < len(m.Details); i++ {
    92  
    93  		if m.Details[i] != nil {
    94  
    95  			if swag.IsZero(m.Details[i]) { // not required
    96  				return nil
    97  			}
    98  
    99  			if err := m.Details[i].ContextValidate(ctx, formats); err != nil {
   100  				if ve, ok := err.(*errors.Validation); ok {
   101  					return ve.ValidateName("details" + "." + strconv.Itoa(i))
   102  				} else if ce, ok := err.(*errors.CompositeError); ok {
   103  					return ce.ValidateName("details" + "." + strconv.Itoa(i))
   104  				}
   105  				return err
   106  			}
   107  		}
   108  
   109  	}
   110  
   111  	return nil
   112  }
   113  
   114  // MarshalBinary interface implementation
   115  func (m *RuntimeError) MarshalBinary() ([]byte, error) {
   116  	if m == nil {
   117  		return nil, nil
   118  	}
   119  	return swag.WriteJSON(m)
   120  }
   121  
   122  // UnmarshalBinary interface implementation
   123  func (m *RuntimeError) UnmarshalBinary(b []byte) error {
   124  	var res RuntimeError
   125  	if err := swag.ReadJSON(b, &res); err != nil {
   126  		return err
   127  	}
   128  	*m = res
   129  	return nil
   130  }