...

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