metrics.go 4.4 KB

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