github.com/kaisawind/go-swagger@v0.19.0/fixtures/goparsing/petstore/rest/app.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 rest
    16  
    17  import (
    18  	"net/http"
    19  
    20  	"github.com/go-openapi/runtime/middleware/denco"
    21  	"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/rest/handlers"
    22  )
    23  
    24  // ServeAPI serves this api
    25  func ServeAPI() error {
    26  	mux := denco.NewMux()
    27  
    28  	routes := []denco.Handler{
    29  		mux.GET("/pets", handlers.GetPets),
    30  		mux.POST("/pets", handlers.CreatePet),
    31  		mux.GET("/pets/:id", handlers.GetPetByID),
    32  		mux.PUT("/pets/:id", handlers.UpdatePet),
    33  		mux.Handler("DELETE", "/pets/:id", handlers.DeletePet),
    34  		mux.GET("/orders/:id", handlers.GetOrderDetails),
    35  		mux.POST("/orders", handlers.CreateOrder),
    36  		mux.PUT("/orders/:id", handlers.UpdateOrder),
    37  		mux.Handler("DELETE", "/orders/:id", handlers.CancelOrder),
    38  	}
    39  	handler, err := mux.Build(routes)
    40  	if err != nil {
    41  		return err
    42  	}
    43  	return http.ListenAndServe(":8000", handler)
    44  }