...

Source file src/github.com/prometheus/alertmanager/api/v2/models/alert.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  
    25  	"github.com/go-openapi/errors"
    26  	"github.com/go-openapi/strfmt"
    27  	"github.com/go-openapi/swag"
    28  	"github.com/go-openapi/validate"
    29  )
    30  
    31  // Alert alert
    32  //
    33  // swagger:model alert
    34  type Alert struct {
    35  
    36  	// generator URL
    37  	// Format: uri
    38  	GeneratorURL strfmt.URI `json:"generatorURL,omitempty"`
    39  
    40  	// labels
    41  	// Required: true
    42  	Labels LabelSet `json:"labels"`
    43  }
    44  
    45  // Validate validates this alert
    46  func (m *Alert) Validate(formats strfmt.Registry) error {
    47  	var res []error
    48  
    49  	if err := m.validateGeneratorURL(formats); err != nil {
    50  		res = append(res, err)
    51  	}
    52  
    53  	if err := m.validateLabels(formats); err != nil {
    54  		res = append(res, err)
    55  	}
    56  
    57  	if len(res) > 0 {
    58  		return errors.CompositeValidationError(res...)
    59  	}
    60  	return nil
    61  }
    62  
    63  func (m *Alert) validateGeneratorURL(formats strfmt.Registry) error {
    64  	if swag.IsZero(m.GeneratorURL) { // not required
    65  		return nil
    66  	}
    67  
    68  	if err := validate.FormatOf("generatorURL", "body", "uri", m.GeneratorURL.String(), formats); err != nil {
    69  		return err
    70  	}
    71  
    72  	return nil
    73  }
    74  
    75  func (m *Alert) validateLabels(formats strfmt.Registry) error {
    76  
    77  	if err := validate.Required("labels", "body", m.Labels); err != nil {
    78  		return err
    79  	}
    80  
    81  	if m.Labels != nil {
    82  		if err := m.Labels.Validate(formats); err != nil {
    83  			if ve, ok := err.(*errors.Validation); ok {
    84  				return ve.ValidateName("labels")
    85  			} else if ce, ok := err.(*errors.CompositeError); ok {
    86  				return ce.ValidateName("labels")
    87  			}
    88  			return err
    89  		}
    90  	}
    91  
    92  	return nil
    93  }
    94  
    95  // ContextValidate validate this alert based on the context it is used
    96  func (m *Alert) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    97  	var res []error
    98  
    99  	if err := m.contextValidateLabels(ctx, formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if len(res) > 0 {
   104  		return errors.CompositeValidationError(res...)
   105  	}
   106  	return nil
   107  }
   108  
   109  func (m *Alert) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {
   110  
   111  	if err := m.Labels.ContextValidate(ctx, formats); err != nil {
   112  		if ve, ok := err.(*errors.Validation); ok {
   113  			return ve.ValidateName("labels")
   114  		} else if ce, ok := err.(*errors.CompositeError); ok {
   115  			return ce.ValidateName("labels")
   116  		}
   117  		return err
   118  	}
   119  
   120  	return nil
   121  }
   122  
   123  // MarshalBinary interface implementation
   124  func (m *Alert) MarshalBinary() ([]byte, error) {
   125  	if m == nil {
   126  		return nil, nil
   127  	}
   128  	return swag.WriteJSON(m)
   129  }
   130  
   131  // UnmarshalBinary interface implementation
   132  func (m *Alert) UnmarshalBinary(b []byte) error {
   133  	var res Alert
   134  	if err := swag.ReadJSON(b, &res); err != nil {
   135  		return err
   136  	}
   137  	*m = res
   138  	return nil
   139  }
   140  

View as plain text