...

Source file src/github.com/prometheus/alertmanager/api/v2/restapi/operations/silence/post_silences_parameters.go

Documentation: github.com/prometheus/alertmanager/api/v2/restapi/operations/silence

     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 silence
    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  	"io"
    24  	"net/http"
    25  
    26  	"github.com/go-openapi/errors"
    27  	"github.com/go-openapi/runtime"
    28  	"github.com/go-openapi/runtime/middleware"
    29  	"github.com/go-openapi/validate"
    30  
    31  	"github.com/prometheus/alertmanager/api/v2/models"
    32  )
    33  
    34  // NewPostSilencesParams creates a new PostSilencesParams object
    35  //
    36  // There are no default values defined in the spec.
    37  func NewPostSilencesParams() PostSilencesParams {
    38  
    39  	return PostSilencesParams{}
    40  }
    41  
    42  // PostSilencesParams contains all the bound params for the post silences operation
    43  // typically these are obtained from a http.Request
    44  //
    45  // swagger:parameters postSilences
    46  type PostSilencesParams struct {
    47  
    48  	// HTTP Request Object
    49  	HTTPRequest *http.Request `json:"-"`
    50  
    51  	/*The silence to create
    52  	  Required: true
    53  	  In: body
    54  	*/
    55  	Silence *models.PostableSilence
    56  }
    57  
    58  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    59  // for simple values it will use straight method calls.
    60  //
    61  // To ensure default values, the struct must have been initialized with NewPostSilencesParams() beforehand.
    62  func (o *PostSilencesParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    63  	var res []error
    64  
    65  	o.HTTPRequest = r
    66  
    67  	if runtime.HasBody(r) {
    68  		defer r.Body.Close()
    69  		var body models.PostableSilence
    70  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    71  			if err == io.EOF {
    72  				res = append(res, errors.Required("silence", "body", ""))
    73  			} else {
    74  				res = append(res, errors.NewParseError("silence", "body", "", err))
    75  			}
    76  		} else {
    77  			// validate body object
    78  			if err := body.Validate(route.Formats); err != nil {
    79  				res = append(res, err)
    80  			}
    81  
    82  			ctx := validate.WithOperationRequest(r.Context())
    83  			if err := body.ContextValidate(ctx, route.Formats); err != nil {
    84  				res = append(res, err)
    85  			}
    86  
    87  			if len(res) == 0 {
    88  				o.Silence = &body
    89  			}
    90  		}
    91  	} else {
    92  		res = append(res, errors.Required("silence", "body", ""))
    93  	}
    94  	if len(res) > 0 {
    95  		return errors.CompositeValidationError(res...)
    96  	}
    97  	return nil
    98  }
    99  

View as plain text