github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/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/enums" 23 "github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/models" 24 ) 25 26 // A GenericError is the default error message that is generated. 27 // For certain status codes there are more appropriate error structures. 28 // 29 // swagger:response genericError 30 type GenericError struct { 31 // in: body 32 Body struct { 33 Code int32 `json:"code"` 34 Message error `json:"message"` 35 } `json:"body"` 36 } 37 38 // A ValidationError is an that is generated for validation failures. 39 // It has the same fields as a generic error but adds a Field property. 40 // 41 // swagger:response validationError 42 type ValidationError struct { 43 // in: body 44 Body struct { 45 Code int32 `json:"code"` 46 Message string `json:"message"` 47 Field string `json:"field"` 48 } `json:"body"` 49 } 50 51 // A PetQueryFlags contains the query flags for things that list pets. 52 // swagger:parameters listPets 53 type PetQueryFlags struct { 54 // Status 55 Status enums.Status `json:"status"` 56 57 // Birthday 58 // 59 // swagger:strfmt date 60 Birthday time.Time `json:"birthday"` 61 } 62 63 // A PetID parameter model. 64 // 65 // This is used for operations that want the ID of an pet in the path 66 // swagger:parameters getPetById deletePet updatePet 67 type PetID struct { 68 // The ID of the pet 69 // 70 // in: path 71 // required: true 72 ID int64 `json:"id"` 73 } 74 75 // A PetBodyParams model. 76 // 77 // This is used for operations that want an Order as body of the request 78 // swagger:parameters updatePet createPet 79 type PetBodyParams struct { 80 // The pet to submit. 81 // 82 // in: body 83 // required: true 84 Pet *models.Pet `json:"pet"` 85 } 86 87 // GetPets swagger:route GET /pets pets listPets 88 // 89 // Lists the pets known to the store. 90 // 91 // By default it will only lists pets that are available for sale. 92 // This can be changed with the status flag. 93 // 94 // Deprecated: true 95 // Responses: 96 // default: genericError 97 // 200: []pet 98 func GetPets(w http.ResponseWriter, r *http.Request, params denco.Params) { 99 // some actual stuff should happen in here 100 } 101 102 // GetPetByID swagger:route GET /pets/{id} pets getPetById 103 // 104 // Gets the details for a pet. 105 // 106 // Responses: 107 // default: genericError 108 // 200: pet 109 func GetPetByID(w http.ResponseWriter, r *http.Request, params denco.Params) { 110 // some actual stuff should happen in here 111 } 112 113 // CreatePet swagger:route POST /pets pets createPet 114 // 115 // Creates a new pet in the store. 116 // 117 // Responses: 118 // default: genericError 119 // 200: pet 120 // 422: validationError 121 func CreatePet(w http.ResponseWriter, r *http.Request, params denco.Params) { 122 // some actual stuff should happen in here 123 } 124 125 // UpdatePet swagger:route PUT /pets/{id} pets updatePet 126 // 127 // Updates the details for a pet. 128 // 129 // Responses: 130 // default: genericError 131 // 200: pet 132 // 422: validationError 133 func UpdatePet(w http.ResponseWriter, r *http.Request, params denco.Params) { 134 // some actual stuff should happen in here 135 } 136 137 // DeletePet swagger:route DELETE /pets/{id} pets deletePet 138 // 139 // Deletes a pet from the store. 140 // 141 // Responses: 142 // default: genericError 143 // 204: 144 func DeletePet(w http.ResponseWriter, r *http.Request, params denco.Params) { 145 // some actual stuff should happen in here 146 }