test

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Code generated by goag (https://github.com/vkd/goag). DO NOT EDIT.

Code generated by goag (https://github.com/vkd/goag). DO NOT EDIT.

Code generated by goag (https://github.com/vkd/goag). DO NOT EDIT.

Code generated by goag (https://github.com/vkd/goag). DO NOT EDIT.

Code generated by goag (https://github.com/vkd/goag). DO NOT EDIT.

Index

Examples

Constants

View Source
const SpecFile string = `` /* 2614-byte string literal not displayed */

Variables

View Source
var LogError = func(err error) {
	log.Println(fmt.Sprintf("Error: %v", err))
}

Functions

func SchemaPath

func SchemaPath(r *http.Request) (string, bool)

func SpecFileHandler

func SpecFileHandler() http.Handler

Types

type API

type API struct {
	ListPetsHandler    ListPetsHandlerFunc
	CreatePetsHandler  CreatePetsHandlerFunc
	ShowPetByIDHandler ShowPetByIDHandlerFunc

	// 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{
		ShowPetByIDHandler: func(ctx context.Context, r ShowPetByIDRequest) ShowPetByIDResponse {
			req, err := r.Parse()
			if err != nil {
				return NewShowPetByIDResponseDefaultJSON(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 NewShowPetByIDResponseDefaultJSON(http.StatusInternalServerError, Error{
					Code:    500,
					Message: fmt.Sprintf("Internal server error: %v", err),
				})
			}

			return NewShowPetByIDResponse200JSON(out)
		},
		// ...
	}

	_ = http.ListenAndServe(":8080", api)
}
Output:

func (*API) ServeHTTP

func (rt *API) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type Client

type Client struct {
	BaseURL    string
	HTTPClient HTTPClient
}

func NewClient

func NewClient(baseURL string, httpClient HTTPClient) *Client

func (*Client) CreatePets added in v0.0.14

func (c *Client) CreatePets(ctx context.Context, request CreatePetsParams) (CreatePetsResponse, error)

CreatePets - POST /pets

func (*Client) ListPets added in v0.0.14

func (c *Client) ListPets(ctx context.Context, request ListPetsParams) (ListPetsResponse, error)

ListPets - GET /pets

func (*Client) ShowPetByID added in v0.0.14

func (c *Client) ShowPetByID(ctx context.Context, request ShowPetByIDParams) (ShowPetByIDResponse, error)

ShowPetByID - GET /pets/{petId}

type CreatePetsHandlerFunc added in v0.0.5

type CreatePetsHandlerFunc func(ctx context.Context, r CreatePetsRequest) CreatePetsResponse

CreatePetsHandlerFunc - Create a pet

func (CreatePetsHandlerFunc) ServeHTTP added in v0.0.5

type CreatePetsParams added in v0.0.5

type CreatePetsParams struct {
}

func (CreatePetsParams) HTTP added in v0.0.5

func (r CreatePetsParams) HTTP() *http.Request

func (CreatePetsParams) Parse added in v0.0.5

type CreatePetsRequest added in v0.0.5

type CreatePetsRequest interface {
	HTTP() *http.Request
	Parse() CreatePetsParams
}

func CreatePetsHTTPRequest added in v0.0.5

func CreatePetsHTTPRequest(r *http.Request) CreatePetsRequest

type CreatePetsResponse added in v0.0.5

type CreatePetsResponse interface {
	// contains filtered or unexported methods
}

func NewCreatePetsResponse201 added in v0.0.5

func NewCreatePetsResponse201() CreatePetsResponse

func NewCreatePetsResponseDefaultJSON added in v0.0.5

func NewCreatePetsResponseDefaultJSON(code int, body Error) CreatePetsResponse

type CreatePetsResponse201 added in v0.0.5

type CreatePetsResponse201 struct{}

CreatePetsResponse201 - Null response

func (CreatePetsResponse201) Write added in v0.0.5

type CreatePetsResponseDefaultJSON added in v0.0.5

type CreatePetsResponseDefaultJSON struct {
	Code int
	Body Error
}

CreatePetsResponseDefaultJSON - unexpected error

func (CreatePetsResponseDefaultJSON) Write added in v0.0.5

type ErrParseParam

type ErrParseParam struct {
	In        string
	Parameter string
	Reason    string
	Err       error
}

func (ErrParseParam) Error

func (e ErrParseParam) Error() string

func (ErrParseParam) Unwrap

func (e ErrParseParam) Unwrap() error

type Error

type Error struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type HTTPClientFunc added in v0.0.14

type HTTPClientFunc func(*http.Request) (*http.Response, error)

func (HTTPClientFunc) Do added in v0.0.14

type ListPetsHandlerFunc added in v0.0.5

type ListPetsHandlerFunc func(ctx context.Context, r ListPetsRequest) ListPetsResponse

ListPetsHandlerFunc - List all pets

func (ListPetsHandlerFunc) ServeHTTP added in v0.0.5

func (f ListPetsHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ListPetsParams added in v0.0.5

type ListPetsParams struct {
	Query struct {

		// Limit - How many items to return at one time (max 100)
		Limit Maybe[int32]
	}
}

func (ListPetsParams) HTTP added in v0.0.5

func (r ListPetsParams) HTTP() *http.Request

func (ListPetsParams) Parse added in v0.0.5

func (r ListPetsParams) Parse() (ListPetsParams, error)

type ListPetsRequest added in v0.0.5

type ListPetsRequest interface {
	HTTP() *http.Request
	Parse() (ListPetsParams, error)
}

func ListPetsHTTPRequest added in v0.0.5

func ListPetsHTTPRequest(r *http.Request) ListPetsRequest

type ListPetsResponse added in v0.0.5

type ListPetsResponse interface {
	// contains filtered or unexported methods
}

func NewListPetsResponse200JSON added in v0.0.5

func NewListPetsResponse200JSON(body Pets, xNext string) ListPetsResponse

func NewListPetsResponseDefaultJSON added in v0.0.5

func NewListPetsResponseDefaultJSON(code int, body Error) ListPetsResponse

type ListPetsResponse200JSON added in v0.0.5

type ListPetsResponse200JSON struct {
	Body    Pets
	Headers struct {
		XNext string
	}
}

ListPetsResponse200JSON - A paged array of pets

func (ListPetsResponse200JSON) Write added in v0.0.5

type ListPetsResponseDefaultJSON added in v0.0.5

type ListPetsResponseDefaultJSON struct {
	Code int
	Body Error
}

ListPetsResponseDefaultJSON - unexpected error

func (ListPetsResponseDefaultJSON) Write added in v0.0.5

type Maybe added in v0.1.5

type Maybe[T any] struct {
	IsSet bool
	Value T
}

func Just added in v0.1.5

func Just[T any](v T) Maybe[T]

func (*Maybe[T]) Set added in v0.1.6

func (m *Maybe[T]) Set(v T)

type Pet

type Pet struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Tag  string `json:"tag"`
}

type Pets

type Pets []Pet

type ShowPetByIDHandlerFunc added in v0.0.5

type ShowPetByIDHandlerFunc func(ctx context.Context, r ShowPetByIDRequest) ShowPetByIDResponse

ShowPetByIDHandlerFunc - Info for a specific pet

func (ShowPetByIDHandlerFunc) ServeHTTP added in v0.0.5

type ShowPetByIDParams added in v0.0.5

type ShowPetByIDParams struct {
	Path struct {

		// PetID - The id of the pet to retrieve
		PetID string
	}
}

func (ShowPetByIDParams) HTTP added in v0.0.5

func (r ShowPetByIDParams) HTTP() *http.Request

func (ShowPetByIDParams) Parse added in v0.0.5

type ShowPetByIDRequest added in v0.0.5

type ShowPetByIDRequest interface {
	HTTP() *http.Request
	Parse() (ShowPetByIDParams, error)
}

func ShowPetByIDHTTPRequest added in v0.0.5

func ShowPetByIDHTTPRequest(r *http.Request) ShowPetByIDRequest

type ShowPetByIDResponse added in v0.0.5

type ShowPetByIDResponse interface {
	// contains filtered or unexported methods
}

func NewShowPetByIDResponse200JSON added in v0.0.5

func NewShowPetByIDResponse200JSON(body Pet) ShowPetByIDResponse

func NewShowPetByIDResponseDefaultJSON added in v0.0.5

func NewShowPetByIDResponseDefaultJSON(code int, body Error) ShowPetByIDResponse

type ShowPetByIDResponse200JSON added in v0.0.5

type ShowPetByIDResponse200JSON struct {
	Body Pet
}

ShowPetByIDResponse200JSON - Expected response to a valid request

func (ShowPetByIDResponse200JSON) Write added in v0.0.5

type ShowPetByIDResponseDefaultJSON added in v0.0.5

type ShowPetByIDResponseDefaultJSON struct {
	Code int
	Body Error
}

ShowPetByIDResponseDefaultJSON - unexpected error

func (ShowPetByIDResponseDefaultJSON) Write added in v0.0.5

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL