Documentation
¶
Index ¶
- Constants
- Variables
- func SchemaPath(r *http.Request) (string, bool)
- func SpecFileHandler() http.Handler
- type API
- type ErrParseParam
- type Error
- type GetPetsHandlerFunc
- type GetPetsParams
- type GetPetsPetIDHandlerFunc
- type GetPetsPetIDParams
- type GetPetsPetIDRequest
- type GetPetsPetIDResponse
- type GetPetsPetIDResponse200JSON
- type GetPetsPetIDResponseDefaultJSON
- type GetPetsRequest
- type GetPetsResponse
- type GetPetsResponse200JSON
- type GetPetsResponseDefaultJSON
- type Pet
- type Pets
- type PostPetsHandlerFunc
- type PostPetsParams
- type PostPetsRequest
- type PostPetsResponse
- type PostPetsResponse201
- type PostPetsResponseDefaultJSON
Examples ¶
Constants ¶
View Source
const SpecFile string = `` /* 2614-byte string literal not displayed */
Variables ¶
Functions ¶
func SpecFileHandler ¶
Types ¶
type API ¶
type API struct {
GetPetsHandler GetPetsHandlerFunc
PostPetsHandler PostPetsHandlerFunc
GetPetsPetIDHandler GetPetsPetIDHandlerFunc
// not found
NotFoundHandler http.Handler
// spec file
SpecFileHandler http.Handler
Middlewares []func(h http.Handler) http.Handler
}
Example (PetsStore) ¶
package main
import (
"context"
"fmt"
"net/http"
)
var db interface {
GetPet(_ context.Context, id string) (Pet, error)
}
func main() {
api := &API{
GetPetsPetIDHandler: func(r GetPetsPetIDRequest) GetPetsPetIDResponse {
req, err := r.Parse()
if err != nil {
return NewGetPetsPetIDResponseDefaultJSON(http.StatusBadRequest, Error{
Code: 400,
Message: fmt.Sprintf("Bad request: %v", err),
})
}
out, err := db.GetPet(r.HTTP().Context(), req.Path.PetID)
if err != nil {
return NewGetPetsPetIDResponseDefaultJSON(http.StatusInternalServerError, Error{
Code: 500,
Message: fmt.Sprintf("Internal server error: %v", err),
})
}
return NewGetPetsPetIDResponse200JSON(out)
},
// ...
}
_ = http.ListenAndServe(":8080", api)
}
Output:
type ErrParseParam ¶
func (ErrParseParam) Error ¶
func (e ErrParseParam) Error() string
func (ErrParseParam) Unwrap ¶
func (e ErrParseParam) Unwrap() error
type GetPetsHandlerFunc ¶
type GetPetsHandlerFunc func(r GetPetsRequest) GetPetsResponse
GetPetsHandlerFunc - List all pets
func (GetPetsHandlerFunc) ServeHTTP ¶
func (f GetPetsHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetPetsParams ¶ added in v0.0.3
type GetPetsParams struct {
Query struct {
// Limit - How many items to return at one time (max 100)
Limit *int32
}
}
func (GetPetsParams) HTTP ¶ added in v0.0.3
func (r GetPetsParams) HTTP() *http.Request
func (GetPetsParams) Parse ¶ added in v0.0.3
func (r GetPetsParams) Parse() (GetPetsParams, error)
type GetPetsPetIDHandlerFunc ¶
type GetPetsPetIDHandlerFunc func(r GetPetsPetIDRequest) GetPetsPetIDResponse
GetPetsPetIDHandlerFunc - Info for a specific pet
func (GetPetsPetIDHandlerFunc) ServeHTTP ¶
func (f GetPetsPetIDHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type GetPetsPetIDParams ¶ added in v0.0.3
type GetPetsPetIDParams struct {
Path struct {
// PetID - The id of the pet to retrieve
PetID string
}
}
func (GetPetsPetIDParams) HTTP ¶ added in v0.0.3
func (r GetPetsPetIDParams) HTTP() *http.Request
func (GetPetsPetIDParams) Parse ¶ added in v0.0.3
func (r GetPetsPetIDParams) Parse() (GetPetsPetIDParams, error)
type GetPetsPetIDRequest ¶
type GetPetsPetIDRequest interface {
HTTP() *http.Request
Parse() (GetPetsPetIDParams, error)
}
func GetPetsPetIDHTTPRequest ¶
func GetPetsPetIDHTTPRequest(r *http.Request) GetPetsPetIDRequest
type GetPetsPetIDResponse ¶
type GetPetsPetIDResponse interface {
Write(w http.ResponseWriter)
// contains filtered or unexported methods
}
func NewGetPetsPetIDResponse200JSON ¶
func NewGetPetsPetIDResponse200JSON(body Pet) GetPetsPetIDResponse
func NewGetPetsPetIDResponseDefaultJSON ¶
func NewGetPetsPetIDResponseDefaultJSON(code int, body Error) GetPetsPetIDResponse
type GetPetsPetIDResponse200JSON ¶
type GetPetsPetIDResponse200JSON struct {
Body Pet
}
GetPetsPetIDResponse200JSON - Expected response to a valid request
func (GetPetsPetIDResponse200JSON) Write ¶
func (r GetPetsPetIDResponse200JSON) Write(w http.ResponseWriter)
type GetPetsPetIDResponseDefaultJSON ¶
GetPetsPetIDResponseDefaultJSON - unexpected error
func (GetPetsPetIDResponseDefaultJSON) Write ¶
func (r GetPetsPetIDResponseDefaultJSON) Write(w http.ResponseWriter)
type GetPetsRequest ¶
type GetPetsRequest interface {
HTTP() *http.Request
Parse() (GetPetsParams, error)
}
func GetPetsHTTPRequest ¶
func GetPetsHTTPRequest(r *http.Request) GetPetsRequest
type GetPetsResponse ¶
type GetPetsResponse interface {
Write(w http.ResponseWriter)
// contains filtered or unexported methods
}
func NewGetPetsResponse200JSON ¶
func NewGetPetsResponse200JSON(body Pets, xNext string) GetPetsResponse
func NewGetPetsResponseDefaultJSON ¶
func NewGetPetsResponseDefaultJSON(code int, body Error) GetPetsResponse
type GetPetsResponse200JSON ¶
GetPetsResponse200JSON - A paged array of pets
func (GetPetsResponse200JSON) Write ¶
func (r GetPetsResponse200JSON) Write(w http.ResponseWriter)
type GetPetsResponseDefaultJSON ¶
GetPetsResponseDefaultJSON - unexpected error
func (GetPetsResponseDefaultJSON) Write ¶
func (r GetPetsResponseDefaultJSON) Write(w http.ResponseWriter)
type PostPetsHandlerFunc ¶
type PostPetsHandlerFunc func(r PostPetsRequest) PostPetsResponse
PostPetsHandlerFunc - Create a pet
func (PostPetsHandlerFunc) ServeHTTP ¶
func (f PostPetsHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PostPetsParams ¶ added in v0.0.3
type PostPetsParams struct {
}
func (PostPetsParams) HTTP ¶ added in v0.0.3
func (r PostPetsParams) HTTP() *http.Request
func (PostPetsParams) Parse ¶ added in v0.0.3
func (r PostPetsParams) Parse() PostPetsParams
type PostPetsRequest ¶
type PostPetsRequest interface {
HTTP() *http.Request
Parse() PostPetsParams
}
func PostPetsHTTPRequest ¶
func PostPetsHTTPRequest(r *http.Request) PostPetsRequest
type PostPetsResponse ¶
type PostPetsResponse interface {
Write(w http.ResponseWriter)
// contains filtered or unexported methods
}
func NewPostPetsResponse201 ¶
func NewPostPetsResponse201() PostPetsResponse
func NewPostPetsResponseDefaultJSON ¶
func NewPostPetsResponseDefaultJSON(code int, body Error) PostPetsResponse
type PostPetsResponse201 ¶
type PostPetsResponse201 struct{}
PostPetsResponse201 - Null response
func (PostPetsResponse201) Write ¶
func (r PostPetsResponse201) Write(w http.ResponseWriter)
type PostPetsResponseDefaultJSON ¶
PostPetsResponseDefaultJSON - unexpected error
func (PostPetsResponseDefaultJSON) Write ¶
func (r PostPetsResponseDefaultJSON) Write(w http.ResponseWriter)
Click to show internal directories.
Click to hide internal directories.