petstore

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname = petstoreapi.Hostname
	Version  = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

func (*Intermediate) BearerToken

func (svc *Intermediate) BearerToken() (value string)

BearerToken is the OAuth2 bearer token presented to the remote Swagger Petstore API.

func (*Intermediate) RemoteBaseURL

func (svc *Intermediate) RemoteBaseURL() (value string)

RemoteBaseURL is the base URL of the remote Swagger Petstore API.

func (*Intermediate) SetBearerToken

func (svc *Intermediate) SetBearerToken(value string) (err error)

SetBearerToken sets the value of the configuration property.

func (*Intermediate) SetRemoteBaseURL

func (svc *Intermediate) SetRemoteBaseURL(value string) (err error)

SetRemoteBaseURL sets the value of the configuration property.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) AddPet

func (svc *Mock) AddPet(ctx context.Context, httpRequestBody *petstoreapi.Pet) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)

AddPet executes the mock handler.

func (*Mock) GetPetById

func (svc *Mock) GetPetById(ctx context.Context, petId int64) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)

GetPetById executes the mock handler.

func (*Mock) MockAddPet

func (svc *Mock) MockAddPet(handler func(ctx context.Context, httpRequestBody *petstoreapi.Pet) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)) *Mock

MockAddPet sets up a mock handler for AddPet.

func (*Mock) MockGetPetById

func (svc *Mock) MockGetPetById(handler func(ctx context.Context, petId int64) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)) *Mock

MockGetPetById sets up a mock handler for GetPetById.

func (*Mock) MockUploadFile

func (svc *Mock) MockUploadFile(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockUploadFile sets up a mock handler for UploadFile.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Mock) UploadFile

func (svc *Mock) UploadFile(w http.ResponseWriter, r *http.Request) (err error)

UploadFile executes the mock handler.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove

}

Service implements petstore which delegates to the Swagger Petstore API.

This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! You can now help us improve the API whether it's by making changes to the definition itself or to the code. That way, with time, we can improve the API in general, and expose some of the new features in OAS3.

Some useful links: - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) AddPet

func (svc *Service) AddPet(ctx context.Context, httpRequestBody *petstoreapi.Pet) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)

AddPet adds a new pet to the store.

Input:

  • httpRequestBody: httpRequestBody is the pet to add

Output:

  • httpResponseBody: httpResponseBody is the created pet
  • httpStatusCode: httpStatusCode is the remote HTTP status code

func (*Service) GetPetById

func (svc *Service) GetPetById(ctx context.Context, petId int64) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)

GetPetById returns a single pet.

Input:

  • petId: petId is the ID of the pet to return

Output:

  • httpResponseBody: httpResponseBody is the requested pet
  • httpStatusCode: httpStatusCode is the remote HTTP status code

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) UploadFile

func (svc *Service) UploadFile(w http.ResponseWriter, r *http.Request) (err error)

UploadFile uploads an image of the pet.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	AddPet(ctx context.Context, httpRequestBody *petstoreapi.Pet) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error) // MARKER: AddPet
	GetPetById(ctx context.Context, petId int64) (httpResponseBody *petstoreapi.Pet, httpStatusCode int, err error)                  // MARKER: GetPetById
	UploadFile(w http.ResponseWriter, r *http.Request) (err error)                                                                   // MARKER: UploadFile
}

ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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