...

Source file src/github.com/prometheus/alertmanager/api/v2/models/cluster_status.go

Documentation: github.com/prometheus/alertmanager/api/v2/models

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Prometheus Team
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  // http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package models
    18  
    19  // This file was generated by the swagger tool.
    20  // Editing this file might prove futile when you re-run the swagger generate command
    21  
    22  import (
    23  	"context"
    24  	"encoding/json"
    25  	"strconv"
    26  
    27  	"github.com/go-openapi/errors"
    28  	"github.com/go-openapi/strfmt"
    29  	"github.com/go-openapi/swag"
    30  	"github.com/go-openapi/validate"
    31  )
    32  
    33  // ClusterStatus cluster status
    34  //
    35  // swagger:model clusterStatus
    36  type ClusterStatus struct {
    37  
    38  	// name
    39  	Name string `json:"name,omitempty"`
    40  
    41  	// peers
    42  	Peers []*PeerStatus `json:"peers"`
    43  
    44  	// status
    45  	// Required: true
    46  	// Enum: [ready settling disabled]
    47  	Status *string `json:"status"`
    48  }
    49  
    50  // Validate validates this cluster status
    51  func (m *ClusterStatus) Validate(formats strfmt.Registry) error {
    52  	var res []error
    53  
    54  	if err := m.validatePeers(formats); err != nil {
    55  		res = append(res, err)
    56  	}
    57  
    58  	if err := m.validateStatus(formats); err != nil {
    59  		res = append(res, err)
    60  	}
    61  
    62  	if len(res) > 0 {
    63  		return errors.CompositeValidationError(res...)
    64  	}
    65  	return nil
    66  }
    67  
    68  func (m *ClusterStatus) validatePeers(formats strfmt.Registry) error {
    69  	if swag.IsZero(m.Peers) { // not required
    70  		return nil
    71  	}
    72  
    73  	for i := 0; i < len(m.Peers); i++ {
    74  		if swag.IsZero(m.Peers[i]) { // not required
    75  			continue
    76  		}
    77  
    78  		if m.Peers[i] != nil {
    79  			if err := m.Peers[i].Validate(formats); err != nil {
    80  				if ve, ok := err.(*errors.Validation); ok {
    81  					return ve.ValidateName("peers" + "." + strconv.Itoa(i))
    82  				} else if ce, ok := err.(*errors.CompositeError); ok {
    83  					return ce.ValidateName("peers" + "." + strconv.Itoa(i))
    84  				}
    85  				return err
    86  			}
    87  		}
    88  
    89  	}
    90  
    91  	return nil
    92  }
    93  
    94  var clusterStatusTypeStatusPropEnum []interface{}
    95  
    96  func init() {
    97  	var res []string
    98  	if err := json.Unmarshal([]byte(`["ready","settling","disabled"]`), &res); err != nil {
    99  		panic(err)
   100  	}
   101  	for _, v := range res {
   102  		clusterStatusTypeStatusPropEnum = append(clusterStatusTypeStatusPropEnum, v)
   103  	}
   104  }
   105  
   106  const (
   107  
   108  	// ClusterStatusStatusReady captures enum value "ready"
   109  	ClusterStatusStatusReady string = "ready"
   110  
   111  	// ClusterStatusStatusSettling captures enum value "settling"
   112  	ClusterStatusStatusSettling string = "settling"
   113  
   114  	// ClusterStatusStatusDisabled captures enum value "disabled"
   115  	ClusterStatusStatusDisabled string = "disabled"
   116  )
   117  
   118  // prop value enum
   119  func (m *ClusterStatus) validateStatusEnum(path, location string, value string) error {
   120  	if err := validate.EnumCase(path, location, value, clusterStatusTypeStatusPropEnum, true); err != nil {
   121  		return err
   122  	}
   123  	return nil
   124  }
   125  
   126  func (m *ClusterStatus) validateStatus(formats strfmt.Registry) error {
   127  
   128  	if err := validate.Required("status", "body", m.Status); err != nil {
   129  		return err
   130  	}
   131  
   132  	// value enum
   133  	if err := m.validateStatusEnum("status", "body", *m.Status); err != nil {
   134  		return err
   135  	}
   136  
   137  	return nil
   138  }
   139  
   140  // ContextValidate validate this cluster status based on the context it is used
   141  func (m *ClusterStatus) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   142  	var res []error
   143  
   144  	if err := m.contextValidatePeers(ctx, formats); err != nil {
   145  		res = append(res, err)
   146  	}
   147  
   148  	if len(res) > 0 {
   149  		return errors.CompositeValidationError(res...)
   150  	}
   151  	return nil
   152  }
   153  
   154  func (m *ClusterStatus) contextValidatePeers(ctx context.Context, formats strfmt.Registry) error {
   155  
   156  	for i := 0; i < len(m.Peers); i++ {
   157  
   158  		if m.Peers[i] != nil {
   159  			if err := m.Peers[i].ContextValidate(ctx, formats); err != nil {
   160  				if ve, ok := err.(*errors.Validation); ok {
   161  					return ve.ValidateName("peers" + "." + strconv.Itoa(i))
   162  				} else if ce, ok := err.(*errors.CompositeError); ok {
   163  					return ce.ValidateName("peers" + "." + strconv.Itoa(i))
   164  				}
   165  				return err
   166  			}
   167  		}
   168  
   169  	}
   170  
   171  	return nil
   172  }
   173  
   174  // MarshalBinary interface implementation
   175  func (m *ClusterStatus) MarshalBinary() ([]byte, error) {
   176  	if m == nil {
   177  		return nil, nil
   178  	}
   179  	return swag.WriteJSON(m)
   180  }
   181  
   182  // UnmarshalBinary interface implementation
   183  func (m *ClusterStatus) UnmarshalBinary(b []byte) error {
   184  	var res ClusterStatus
   185  	if err := swag.ReadJSON(b, &res); err != nil {
   186  		return err
   187  	}
   188  	*m = res
   189  	return nil
   190  }
   191  

View as plain text