...

Source file src/github.com/prometheus/alertmanager/api/v2/models/silence.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  // Silence silence
    32  //
    33  // swagger:model silence
    34  type Silence struct {
    35  
    36  	// comment
    37  	// Required: true
    38  	Comment *string `json:"comment"`
    39  
    40  	// created by
    41  	// Required: true
    42  	CreatedBy *string `json:"createdBy"`
    43  
    44  	// ends at
    45  	// Required: true
    46  	// Format: date-time
    47  	EndsAt *strfmt.DateTime `json:"endsAt"`
    48  
    49  	// matchers
    50  	// Required: true
    51  	Matchers Matchers `json:"matchers"`
    52  
    53  	// starts at
    54  	// Required: true
    55  	// Format: date-time
    56  	StartsAt *strfmt.DateTime `json:"startsAt"`
    57  }
    58  
    59  // Validate validates this silence
    60  func (m *Silence) Validate(formats strfmt.Registry) error {
    61  	var res []error
    62  
    63  	if err := m.validateComment(formats); err != nil {
    64  		res = append(res, err)
    65  	}
    66  
    67  	if err := m.validateCreatedBy(formats); err != nil {
    68  		res = append(res, err)
    69  	}
    70  
    71  	if err := m.validateEndsAt(formats); err != nil {
    72  		res = append(res, err)
    73  	}
    74  
    75  	if err := m.validateMatchers(formats); err != nil {
    76  		res = append(res, err)
    77  	}
    78  
    79  	if err := m.validateStartsAt(formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if len(res) > 0 {
    84  		return errors.CompositeValidationError(res...)
    85  	}
    86  	return nil
    87  }
    88  
    89  func (m *Silence) validateComment(formats strfmt.Registry) error {
    90  
    91  	if err := validate.Required("comment", "body", m.Comment); err != nil {
    92  		return err
    93  	}
    94  
    95  	return nil
    96  }
    97  
    98  func (m *Silence) validateCreatedBy(formats strfmt.Registry) error {
    99  
   100  	if err := validate.Required("createdBy", "body", m.CreatedBy); err != nil {
   101  		return err
   102  	}
   103  
   104  	return nil
   105  }
   106  
   107  func (m *Silence) validateEndsAt(formats strfmt.Registry) error {
   108  
   109  	if err := validate.Required("endsAt", "body", m.EndsAt); err != nil {
   110  		return err
   111  	}
   112  
   113  	if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
   114  		return err
   115  	}
   116  
   117  	return nil
   118  }
   119  
   120  func (m *Silence) validateMatchers(formats strfmt.Registry) error {
   121  
   122  	if err := validate.Required("matchers", "body", m.Matchers); err != nil {
   123  		return err
   124  	}
   125  
   126  	if err := m.Matchers.Validate(formats); err != nil {
   127  		if ve, ok := err.(*errors.Validation); ok {
   128  			return ve.ValidateName("matchers")
   129  		} else if ce, ok := err.(*errors.CompositeError); ok {
   130  			return ce.ValidateName("matchers")
   131  		}
   132  		return err
   133  	}
   134  
   135  	return nil
   136  }
   137  
   138  func (m *Silence) validateStartsAt(formats strfmt.Registry) error {
   139  
   140  	if err := validate.Required("startsAt", "body", m.StartsAt); err != nil {
   141  		return err
   142  	}
   143  
   144  	if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
   145  		return err
   146  	}
   147  
   148  	return nil
   149  }
   150  
   151  // ContextValidate validate this silence based on the context it is used
   152  func (m *Silence) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   153  	var res []error
   154  
   155  	if err := m.contextValidateMatchers(ctx, formats); err != nil {
   156  		res = append(res, err)
   157  	}
   158  
   159  	if len(res) > 0 {
   160  		return errors.CompositeValidationError(res...)
   161  	}
   162  	return nil
   163  }
   164  
   165  func (m *Silence) contextValidateMatchers(ctx context.Context, formats strfmt.Registry) error {
   166  
   167  	if err := m.Matchers.ContextValidate(ctx, formats); err != nil {
   168  		if ve, ok := err.(*errors.Validation); ok {
   169  			return ve.ValidateName("matchers")
   170  		} else if ce, ok := err.(*errors.CompositeError); ok {
   171  			return ce.ValidateName("matchers")
   172  		}
   173  		return err
   174  	}
   175  
   176  	return nil
   177  }
   178  
   179  // MarshalBinary interface implementation
   180  func (m *Silence) MarshalBinary() ([]byte, error) {
   181  	if m == nil {
   182  		return nil, nil
   183  	}
   184  	return swag.WriteJSON(m)
   185  }
   186  
   187  // UnmarshalBinary interface implementation
   188  func (m *Silence) UnmarshalBinary(b []byte) error {
   189  	var res Silence
   190  	if err := swag.ReadJSON(b, &res); err != nil {
   191  		return err
   192  	}
   193  	*m = res
   194  	return nil
   195  }
   196  

View as plain text