github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-shared/v1/models/google_rpc_status.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 // GoogleRPCStatus The `Status` type defines a logical error model that is suitable for 18 // different programming environments, including REST APIs and RPC APIs. It is 19 // used by [gRPC](https://github.com/grpc). The error model is designed to be: 20 // 21 // - Simple to use and understand for most users 22 // - Flexible enough to meet unexpected needs 23 // 24 // # Overview 25 // 26 // The `Status` message contains three pieces of data: error code, error 27 // message, and error details. The error code should be an enum value of 28 // [google.rpc.Code][google.rpc.Code], but it may accept additional error codes 29 // if needed. The error message should be a developer-facing English message 30 // that helps developers *understand* and *resolve* the error. If a localized 31 // user-facing error message is needed, put the localized message in the error 32 // details or localize it in the client. The optional error details may contain 33 // arbitrary information about the error. There is a predefined set of error 34 // detail types in the package `google.rpc` that can be used for common error 35 // conditions. 36 // 37 // # Language mapping 38 // 39 // The `Status` message is the logical representation of the error model, but it 40 // is not necessarily the actual wire format. When the `Status` message is 41 // exposed in different client libraries and different wire protocols, it can be 42 // mapped differently. For example, it will likely be mapped to some exceptions 43 // in Java, but more likely mapped to some error codes in C. 44 // 45 // # Other uses 46 // 47 // The error model and the `Status` message can be used in a variety of 48 // environments, either with or without APIs, to provide a 49 // consistent developer experience across different environments. 50 // 51 // Example uses of this error model include: 52 // 53 // - Partial errors. If a service needs to return partial errors to the client, 54 // it may embed the `Status` in the normal response to indicate the partial 55 // errors. 56 // 57 // - Workflow errors. A typical workflow has multiple steps. Each step may 58 // have a `Status` message for error reporting. 59 // 60 // - Batch operations. If a client uses batch request and batch response, the 61 // `Status` message should be used directly inside batch response, one for 62 // each error sub-response. 63 // 64 // - Asynchronous operations. If an API call embeds asynchronous operation 65 // results in its response, the status of those operations should be 66 // represented directly using the `Status` message. 67 // 68 // - Logging. If some API errors are stored in logs, the message `Status` could 69 // be used directly after any stripping needed for security/privacy reasons. 70 // 71 // swagger:model google.rpc.Status 72 type GoogleRPCStatus struct { 73 74 // The status code, which should be an enum value of 75 // [google.rpc.Code][google.rpc.Code]. 76 Code int32 `json:"code,omitempty"` 77 78 // A list of messages that carry the error details. There is a common set of 79 // message types for APIs to use. 80 Details []*GoogleProtobufAny `json:"details"` 81 82 // A developer-facing error message, which should be in English. Any 83 // user-facing error message should be localized and sent in the 84 // [google.rpc.Status.details][google.rpc.Status.details] field, or localized 85 // by the client. 86 Message string `json:"message,omitempty"` 87 } 88 89 // Validate validates this google rpc status 90 func (m *GoogleRPCStatus) Validate(formats strfmt.Registry) error { 91 var res []error 92 93 if err := m.validateDetails(formats); err != nil { 94 res = append(res, err) 95 } 96 97 if len(res) > 0 { 98 return errors.CompositeValidationError(res...) 99 } 100 return nil 101 } 102 103 func (m *GoogleRPCStatus) validateDetails(formats strfmt.Registry) error { 104 if swag.IsZero(m.Details) { // not required 105 return nil 106 } 107 108 for i := 0; i < len(m.Details); i++ { 109 if swag.IsZero(m.Details[i]) { // not required 110 continue 111 } 112 113 if m.Details[i] != nil { 114 if err := m.Details[i].Validate(formats); err != nil { 115 if ve, ok := err.(*errors.Validation); ok { 116 return ve.ValidateName("details" + "." + strconv.Itoa(i)) 117 } else if ce, ok := err.(*errors.CompositeError); ok { 118 return ce.ValidateName("details" + "." + strconv.Itoa(i)) 119 } 120 return err 121 } 122 } 123 124 } 125 126 return nil 127 } 128 129 // ContextValidate validate this google rpc status based on the context it is used 130 func (m *GoogleRPCStatus) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 131 var res []error 132 133 if err := m.contextValidateDetails(ctx, formats); err != nil { 134 res = append(res, err) 135 } 136 137 if len(res) > 0 { 138 return errors.CompositeValidationError(res...) 139 } 140 return nil 141 } 142 143 func (m *GoogleRPCStatus) contextValidateDetails(ctx context.Context, formats strfmt.Registry) error { 144 145 for i := 0; i < len(m.Details); i++ { 146 147 if m.Details[i] != nil { 148 149 if swag.IsZero(m.Details[i]) { // not required 150 return nil 151 } 152 153 if err := m.Details[i].ContextValidate(ctx, formats); err != nil { 154 if ve, ok := err.(*errors.Validation); ok { 155 return ve.ValidateName("details" + "." + strconv.Itoa(i)) 156 } else if ce, ok := err.(*errors.CompositeError); ok { 157 return ce.ValidateName("details" + "." + strconv.Itoa(i)) 158 } 159 return err 160 } 161 } 162 163 } 164 165 return nil 166 } 167 168 // MarshalBinary interface implementation 169 func (m *GoogleRPCStatus) MarshalBinary() ([]byte, error) { 170 if m == nil { 171 return nil, nil 172 } 173 return swag.WriteJSON(m) 174 } 175 176 // UnmarshalBinary interface implementation 177 func (m *GoogleRPCStatus) UnmarshalBinary(b []byte) error { 178 var res GoogleRPCStatus 179 if err := swag.ReadJSON(b, &res); err != nil { 180 return err 181 } 182 *m = res 183 return nil 184 }