...

Source file src/github.com/prometheus/alertmanager/api/v2/models/matchers.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  	"strconv"
    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  // Matchers matchers
    33  //
    34  // swagger:model matchers
    35  type Matchers []*Matcher
    36  
    37  // Validate validates this matchers
    38  func (m Matchers) Validate(formats strfmt.Registry) error {
    39  	var res []error
    40  
    41  	iMatchersSize := int64(len(m))
    42  
    43  	if err := validate.MinItems("", "body", iMatchersSize, 1); err != nil {
    44  		return err
    45  	}
    46  
    47  	for i := 0; i < len(m); i++ {
    48  		if swag.IsZero(m[i]) { // not required
    49  			continue
    50  		}
    51  
    52  		if m[i] != nil {
    53  			if err := m[i].Validate(formats); err != nil {
    54  				if ve, ok := err.(*errors.Validation); ok {
    55  					return ve.ValidateName(strconv.Itoa(i))
    56  				} else if ce, ok := err.(*errors.CompositeError); ok {
    57  					return ce.ValidateName(strconv.Itoa(i))
    58  				}
    59  				return err
    60  			}
    61  		}
    62  
    63  	}
    64  
    65  	if len(res) > 0 {
    66  		return errors.CompositeValidationError(res...)
    67  	}
    68  	return nil
    69  }
    70  
    71  // ContextValidate validate this matchers based on the context it is used
    72  func (m Matchers) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    73  	var res []error
    74  
    75  	for i := 0; i < len(m); i++ {
    76  
    77  		if m[i] != nil {
    78  			if err := m[i].ContextValidate(ctx, formats); err != nil {
    79  				if ve, ok := err.(*errors.Validation); ok {
    80  					return ve.ValidateName(strconv.Itoa(i))
    81  				} else if ce, ok := err.(*errors.CompositeError); ok {
    82  					return ce.ValidateName(strconv.Itoa(i))
    83  				}
    84  				return err
    85  			}
    86  		}
    87  
    88  	}
    89  
    90  	if len(res) > 0 {
    91  		return errors.CompositeValidationError(res...)
    92  	}
    93  	return nil
    94  }
    95  

View as plain text