github.com/emreu/go-swagger@v0.22.1/fixtures/goparsing/petstore/rest/handlers/pets.go (about)

     1  // Copyright 2015 go-swagger maintainers
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package handlers
    16  
    17  import (
    18  	"net/http"
    19  	"time"
    20  
    21  	"github.com/go-openapi/runtime/middleware/denco"
    22  	"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/models"
    23  )
    24  
    25  // A GenericError is the default error message that is generated.
    26  // For certain status codes there are more appropriate error structures.
    27  //
    28  // swagger:response genericError
    29  type GenericError struct {
    30  	// in: body
    31  	Body struct {
    32  		Code    int32 `json:"code"`
    33  		Message error `json:"message"`
    34  	} `json:"body"`
    35  }
    36  
    37  // A ValidationError is an that is generated for validation failures.
    38  // It has the same fields as a generic error but adds a Field property.
    39  //
    40  // swagger:response validationError
    41  type ValidationError struct {
    42  	// in: body
    43  	Body struct {
    44  		Code    int32  `json:"code"`
    45  		Message string `json:"message"`
    46  		Field   string `json:"field"`
    47  	} `json:"body"`
    48  }
    49  
    50  // A PetQueryFlags contains the query flags for things that list pets.
    51  // swagger:parameters listPets
    52  type PetQueryFlags struct {
    53  	// Status
    54  	Status string `json:"status"`
    55  
    56  	// Birthday
    57  	//
    58  	// swagger:strfmt date
    59  	Birthday time.Time `json:"birthday"`
    60  }
    61  
    62  // A PetID parameter model.
    63  //
    64  // This is used for operations that want the ID of an pet in the path
    65  // swagger:parameters getPetById deletePet updatePet
    66  type PetID struct {
    67  	// The ID of the pet
    68  	//
    69  	// in: path
    70  	// required: true
    71  	ID int64 `json:"id"`
    72  }
    73  
    74  // A PetBodyParams model.
    75  //
    76  // This is used for operations that want an Order as body of the request
    77  // swagger:parameters updatePet createPet
    78  type PetBodyParams struct {
    79  	// The pet to submit.
    80  	//
    81  	// in: body
    82  	// required: true
    83  	Pet *models.Pet `json:"pet"`
    84  }
    85  
    86  // GetPets swagger:route GET /pets pets listPets
    87  //
    88  // Lists the pets known to the store.
    89  //
    90  // By default it will only lists pets that are available for sale.
    91  // This can be changed with the status flag.
    92  //
    93  // Deprecated: true
    94  // Responses:
    95  // 		default: genericError
    96  // 		    200: []pet
    97  func GetPets(w http.ResponseWriter, r *http.Request, params denco.Params) {
    98  	// some actual stuff should happen in here
    99  }
   100  
   101  // GetPetByID swagger:route GET /pets/{id} pets getPetById
   102  //
   103  // Gets the details for a pet.
   104  //
   105  // Responses:
   106  //    default: genericError
   107  //        200: pet
   108  func GetPetByID(w http.ResponseWriter, r *http.Request, params denco.Params) {
   109  	// some actual stuff should happen in here
   110  }
   111  
   112  // CreatePet swagger:route POST /pets pets createPet
   113  //
   114  // Creates a new pet in the store.
   115  //
   116  // Responses:
   117  //    default: genericError
   118  //        200: pet
   119  //        422: validationError
   120  func CreatePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   121  	// some actual stuff should happen in here
   122  }
   123  
   124  // UpdatePet swagger:route PUT /pets/{id} pets updatePet
   125  //
   126  // Updates the details for a pet.
   127  //
   128  // Responses:
   129  //    default: genericError
   130  //        200: pet
   131  //        422: validationError
   132  func UpdatePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   133  	// some actual stuff should happen in here
   134  }
   135  
   136  // DeletePet swagger:route DELETE /pets/{id} pets deletePet
   137  //
   138  // Deletes a pet from the store.
   139  //
   140  // Responses:
   141  //    default: genericError
   142  //        204:
   143  func DeletePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   144  	// some actual stuff should happen in here
   145  }