...

Source file src/github.com/prometheus/alertmanager/api/v2/models/postable_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  // PostableAlert postable alert
    32  //
    33  // swagger:model postableAlert
    34  type PostableAlert struct {
    35  
    36  	// annotations
    37  	Annotations LabelSet `json:"annotations,omitempty"`
    38  
    39  	// ends at
    40  	// Format: date-time
    41  	EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
    42  
    43  	// starts at
    44  	// Format: date-time
    45  	StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
    46  
    47  	Alert
    48  }
    49  
    50  // UnmarshalJSON unmarshals this object from a JSON structure
    51  func (m *PostableAlert) UnmarshalJSON(raw []byte) error {
    52  	// AO0
    53  	var dataAO0 struct {
    54  		Annotations LabelSet `json:"annotations,omitempty"`
    55  
    56  		EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
    57  
    58  		StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
    59  	}
    60  	if err := swag.ReadJSON(raw, &dataAO0); err != nil {
    61  		return err
    62  	}
    63  
    64  	m.Annotations = dataAO0.Annotations
    65  
    66  	m.EndsAt = dataAO0.EndsAt
    67  
    68  	m.StartsAt = dataAO0.StartsAt
    69  
    70  	// AO1
    71  	var aO1 Alert
    72  	if err := swag.ReadJSON(raw, &aO1); err != nil {
    73  		return err
    74  	}
    75  	m.Alert = aO1
    76  
    77  	return nil
    78  }
    79  
    80  // MarshalJSON marshals this object to a JSON structure
    81  func (m PostableAlert) MarshalJSON() ([]byte, error) {
    82  	_parts := make([][]byte, 0, 2)
    83  
    84  	var dataAO0 struct {
    85  		Annotations LabelSet `json:"annotations,omitempty"`
    86  
    87  		EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
    88  
    89  		StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
    90  	}
    91  
    92  	dataAO0.Annotations = m.Annotations
    93  
    94  	dataAO0.EndsAt = m.EndsAt
    95  
    96  	dataAO0.StartsAt = m.StartsAt
    97  
    98  	jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
    99  	if errAO0 != nil {
   100  		return nil, errAO0
   101  	}
   102  	_parts = append(_parts, jsonDataAO0)
   103  
   104  	aO1, err := swag.WriteJSON(m.Alert)
   105  	if err != nil {
   106  		return nil, err
   107  	}
   108  	_parts = append(_parts, aO1)
   109  	return swag.ConcatJSON(_parts...), nil
   110  }
   111  
   112  // Validate validates this postable alert
   113  func (m *PostableAlert) Validate(formats strfmt.Registry) error {
   114  	var res []error
   115  
   116  	if err := m.validateAnnotations(formats); err != nil {
   117  		res = append(res, err)
   118  	}
   119  
   120  	if err := m.validateEndsAt(formats); err != nil {
   121  		res = append(res, err)
   122  	}
   123  
   124  	if err := m.validateStartsAt(formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	// validation for a type composition with Alert
   129  	if err := m.Alert.Validate(formats); err != nil {
   130  		res = append(res, err)
   131  	}
   132  
   133  	if len(res) > 0 {
   134  		return errors.CompositeValidationError(res...)
   135  	}
   136  	return nil
   137  }
   138  
   139  func (m *PostableAlert) validateAnnotations(formats strfmt.Registry) error {
   140  
   141  	if swag.IsZero(m.Annotations) { // not required
   142  		return nil
   143  	}
   144  
   145  	if m.Annotations != nil {
   146  		if err := m.Annotations.Validate(formats); err != nil {
   147  			if ve, ok := err.(*errors.Validation); ok {
   148  				return ve.ValidateName("annotations")
   149  			} else if ce, ok := err.(*errors.CompositeError); ok {
   150  				return ce.ValidateName("annotations")
   151  			}
   152  			return err
   153  		}
   154  	}
   155  
   156  	return nil
   157  }
   158  
   159  func (m *PostableAlert) validateEndsAt(formats strfmt.Registry) error {
   160  
   161  	if swag.IsZero(m.EndsAt) { // not required
   162  		return nil
   163  	}
   164  
   165  	if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
   166  		return err
   167  	}
   168  
   169  	return nil
   170  }
   171  
   172  func (m *PostableAlert) validateStartsAt(formats strfmt.Registry) error {
   173  
   174  	if swag.IsZero(m.StartsAt) { // not required
   175  		return nil
   176  	}
   177  
   178  	if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
   179  		return err
   180  	}
   181  
   182  	return nil
   183  }
   184  
   185  // ContextValidate validate this postable alert based on the context it is used
   186  func (m *PostableAlert) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   187  	var res []error
   188  
   189  	if err := m.contextValidateAnnotations(ctx, formats); err != nil {
   190  		res = append(res, err)
   191  	}
   192  
   193  	// validation for a type composition with Alert
   194  	if err := m.Alert.ContextValidate(ctx, formats); err != nil {
   195  		res = append(res, err)
   196  	}
   197  
   198  	if len(res) > 0 {
   199  		return errors.CompositeValidationError(res...)
   200  	}
   201  	return nil
   202  }
   203  
   204  func (m *PostableAlert) contextValidateAnnotations(ctx context.Context, formats strfmt.Registry) error {
   205  
   206  	if err := m.Annotations.ContextValidate(ctx, formats); err != nil {
   207  		if ve, ok := err.(*errors.Validation); ok {
   208  			return ve.ValidateName("annotations")
   209  		} else if ce, ok := err.(*errors.CompositeError); ok {
   210  			return ce.ValidateName("annotations")
   211  		}
   212  		return err
   213  	}
   214  
   215  	return nil
   216  }
   217  
   218  // MarshalBinary interface implementation
   219  func (m *PostableAlert) MarshalBinary() ([]byte, error) {
   220  	if m == nil {
   221  		return nil, nil
   222  	}
   223  	return swag.WriteJSON(m)
   224  }
   225  
   226  // UnmarshalBinary interface implementation
   227  func (m *PostableAlert) UnmarshalBinary(b []byte) error {
   228  	var res PostableAlert
   229  	if err := swag.ReadJSON(b, &res); err != nil {
   230  		return err
   231  	}
   232  	*m = res
   233  	return nil
   234  }
   235  

View as plain text