github.com/kaisawind/go-swagger@v0.19.0/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  // Responses:
    94  // 		default: genericError
    95  // 		    200: []pet
    96  func GetPets(w http.ResponseWriter, r *http.Request, params denco.Params) {
    97  	// some actual stuff should happen in here
    98  }
    99  
   100  // GetPetByID swagger:route GET /pets/{id} pets getPetById
   101  //
   102  // Gets the details for a pet.
   103  //
   104  // Responses:
   105  //    default: genericError
   106  //        200: pet
   107  func GetPetByID(w http.ResponseWriter, r *http.Request, params denco.Params) {
   108  	// some actual stuff should happen in here
   109  }
   110  
   111  // CreatePet swagger:route POST /pets pets createPet
   112  //
   113  // Creates a new pet in the store.
   114  //
   115  // Responses:
   116  //    default: genericError
   117  //        200: pet
   118  //        422: validationError
   119  func CreatePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   120  	// some actual stuff should happen in here
   121  }
   122  
   123  // UpdatePet swagger:route PUT /pets/{id} pets updatePet
   124  //
   125  // Updates the details for a pet.
   126  //
   127  // Responses:
   128  //    default: genericError
   129  //        200: pet
   130  //        422: validationError
   131  func UpdatePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   132  	// some actual stuff should happen in here
   133  }
   134  
   135  // DeletePet swagger:route DELETE /pets/{id} pets deletePet
   136  //
   137  // Deletes a pet from the store.
   138  //
   139  // Responses:
   140  //    default: genericError
   141  //        204:
   142  func DeletePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   143  	// some actual stuff should happen in here
   144  }