api

package
v0.0.0-...-2c50256 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithServerURL

func WithServerURL(ctx context.Context, u *url.URL) context.Context

WithServerURL sets context key to override server URL.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements OAS client.

func NewClient

func NewClient(serverURL string, opts ...ClientOption) (*Client, error)

NewClient initializes new Client defined by OAS.

func (*Client) CreatePets

func (c *Client) CreatePets(ctx context.Context) error

CreatePets invokes createPets operation.

Create a pet.

POST /pets

func (*Client) ListPets

func (c *Client) ListPets(ctx context.Context, params ListPetsParams) (*PetsHeaders, error)

ListPets invokes listPets operation.

List all pets.

GET /pets

func (*Client) ShowPetById

func (c *Client) ShowPetById(ctx context.Context, params ShowPetByIdParams) (*Pet, error)

ShowPetById invokes showPetById operation.

Info for a specific pet.

GET /pets/{petId}

type ClientOption

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

ClientOption is client config option.

func WithClient

func WithClient(client ht.Client) ClientOption

WithClient specifies http client to use.

type CreatePetsCreated

type CreatePetsCreated struct{}

CreatePetsCreated is response for CreatePets operation.

type Error

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

Ref: #/components/schemas/Error

func (*Error) Decode

func (s *Error) Decode(d *jx.Decoder) error

Decode decodes Error from json.

func (*Error) Encode

func (s *Error) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*Error) GetCode

func (s *Error) GetCode() int32

GetCode returns the value of Code.

func (*Error) GetMessage

func (s *Error) GetMessage() string

GetMessage returns the value of Message.

func (*Error) MarshalJSON

func (s *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*Error) SetCode

func (s *Error) SetCode(val int32)

SetCode sets the value of Code.

func (*Error) SetFake

func (s *Error) SetFake()

SetFake set fake values.

func (*Error) SetMessage

func (s *Error) SetMessage(val string)

SetMessage sets the value of Message.

func (*Error) UnmarshalJSON

func (s *Error) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type ErrorStatusCode

type ErrorStatusCode struct {
	StatusCode int
	Response   Error
}

ErrorStatusCode wraps Error with StatusCode.

func (*ErrorStatusCode) Error

func (s *ErrorStatusCode) Error() string

func (*ErrorStatusCode) GetResponse

func (s *ErrorStatusCode) GetResponse() Error

GetResponse returns the value of Response.

func (*ErrorStatusCode) GetStatusCode

func (s *ErrorStatusCode) GetStatusCode() int

GetStatusCode returns the value of StatusCode.

func (*ErrorStatusCode) SetResponse

func (s *ErrorStatusCode) SetResponse(val Error)

SetResponse sets the value of Response.

func (*ErrorStatusCode) SetStatusCode

func (s *ErrorStatusCode) SetStatusCode(val int)

SetStatusCode sets the value of StatusCode.

type Handler

type Handler interface {
	// CreatePets implements createPets operation.
	//
	// Create a pet.
	//
	// POST /pets
	CreatePets(ctx context.Context) error
	// ListPets implements listPets operation.
	//
	// List all pets.
	//
	// GET /pets
	ListPets(ctx context.Context, params ListPetsParams) (*PetsHeaders, error)
	// ShowPetById implements showPetById operation.
	//
	// Info for a specific pet.
	//
	// GET /pets/{petId}
	ShowPetById(ctx context.Context, params ShowPetByIdParams) (*Pet, error)
	// NewError creates *ErrorStatusCode from error returned by handler.
	//
	// Used for common default response.
	NewError(ctx context.Context, err error) *ErrorStatusCode
}

Handler handles operations described by OpenAPI v3 specification.

type Invoker

type Invoker interface {
	// CreatePets invokes createPets operation.
	//
	// Create a pet.
	//
	// POST /pets
	CreatePets(ctx context.Context) error
	// ListPets invokes listPets operation.
	//
	// List all pets.
	//
	// GET /pets
	ListPets(ctx context.Context, params ListPetsParams) (*PetsHeaders, error)
	// ShowPetById invokes showPetById operation.
	//
	// Info for a specific pet.
	//
	// GET /pets/{petId}
	ShowPetById(ctx context.Context, params ShowPetByIdParams) (*Pet, error)
}

Invoker invokes operations described by OpenAPI v3 specification.

type ListPetsParams

type ListPetsParams struct {
	// How many items to return at one time (max 100).
	Limit OptInt32
}

ListPetsParams is parameters of listPets operation.

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type OptInt32

type OptInt32 struct {
	Value int32
	Set   bool
}

OptInt32 is optional int32.

func NewOptInt32

func NewOptInt32(v int32) OptInt32

NewOptInt32 returns new OptInt32 with value set to v.

func (OptInt32) Get

func (o OptInt32) Get() (v int32, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptInt32) IsSet

func (o OptInt32) IsSet() bool

IsSet returns true if OptInt32 was set.

func (OptInt32) Or

func (o OptInt32) Or(d int32) int32

Or returns value if set, or given parameter if does not.

func (*OptInt32) Reset

func (o *OptInt32) Reset()

Reset unsets value.

func (*OptInt32) SetTo

func (o *OptInt32) SetTo(v int32)

SetTo sets value to v.

type OptString

type OptString struct {
	Value string
	Set   bool
}

OptString is optional string.

func NewOptString

func NewOptString(v string) OptString

NewOptString returns new OptString with value set to v.

func (*OptString) Decode

func (o *OptString) Decode(d *jx.Decoder) error

Decode decodes string from json.

func (OptString) Encode

func (o OptString) Encode(e *jx.Encoder)

Encode encodes string as json.

func (OptString) Get

func (o OptString) Get() (v string, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptString) IsSet

func (o OptString) IsSet() bool

IsSet returns true if OptString was set.

func (OptString) MarshalJSON

func (s OptString) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (OptString) Or

func (o OptString) Or(d string) string

Or returns value if set, or given parameter if does not.

func (*OptString) Reset

func (o *OptString) Reset()

Reset unsets value.

func (*OptString) SetFake

func (s *OptString) SetFake()

SetFake set fake values.

func (*OptString) SetTo

func (o *OptString) SetTo(v string)

SetTo sets value to v.

func (*OptString) UnmarshalJSON

func (s *OptString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

type Option

type Option interface {
	ServerOption
	ClientOption
}

Option is config option.

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

WithMeterProvider specifies a meter provider to use for creating a meter.

If none is specified, the otel.GetMeterProvider() is used.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer.

If none is specified, the global provider is used.

type Pet

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

Ref: #/components/schemas/Pet

func (*Pet) Decode

func (s *Pet) Decode(d *jx.Decoder) error

Decode decodes Pet from json.

func (*Pet) Encode

func (s *Pet) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*Pet) GetID

func (s *Pet) GetID() int64

GetID returns the value of ID.

func (*Pet) GetName

func (s *Pet) GetName() string

GetName returns the value of Name.

func (*Pet) GetTag

func (s *Pet) GetTag() OptString

GetTag returns the value of Tag.

func (*Pet) MarshalJSON

func (s *Pet) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*Pet) SetFake

func (s *Pet) SetFake()

SetFake set fake values.

func (*Pet) SetID

func (s *Pet) SetID(val int64)

SetID sets the value of ID.

func (*Pet) SetName

func (s *Pet) SetName(val string)

SetName sets the value of Name.

func (*Pet) SetTag

func (s *Pet) SetTag(val OptString)

SetTag sets the value of Tag.

func (*Pet) UnmarshalJSON

func (s *Pet) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

type Pets

type Pets []Pet

func (*Pets) Decode

func (s *Pets) Decode(d *jx.Decoder) error

Decode decodes Pets from json.

func (Pets) Encode

func (s Pets) Encode(e *jx.Encoder)

Encode encodes Pets as json.

func (Pets) MarshalJSON

func (s Pets) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*Pets) SetFake

func (s *Pets) SetFake()

SetFake set fake values.

func (*Pets) UnmarshalJSON

func (s *Pets) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

func (Pets) Validate

func (s Pets) Validate() error

type PetsHeaders

type PetsHeaders struct {
	XNext    OptString
	Response Pets
}

PetsHeaders wraps Pets with response headers.

func (*PetsHeaders) GetResponse

func (s *PetsHeaders) GetResponse() Pets

GetResponse returns the value of Response.

func (*PetsHeaders) GetXNext

func (s *PetsHeaders) GetXNext() OptString

GetXNext returns the value of XNext.

func (*PetsHeaders) SetResponse

func (s *PetsHeaders) SetResponse(val Pets)

SetResponse sets the value of Response.

func (*PetsHeaders) SetXNext

func (s *PetsHeaders) SetXNext(val OptString)

SetXNext sets the value of XNext.

func (*PetsHeaders) Validate

func (s *PetsHeaders) Validate() error

type Route

type Route struct {
	// contains filtered or unexported fields
}

Route is route object.

func (Route) Args

func (r Route) Args() []string

Args returns parsed arguments.

func (Route) Name

func (r Route) Name() string

Name returns ogen operation name.

It is guaranteed to be unique and not empty.

func (Route) OperationID

func (r Route) OperationID() string

OperationID returns OpenAPI operationId.

func (Route) PathPattern

func (r Route) PathPattern() string

PathPattern returns OpenAPI path.

func (Route) Summary

func (r Route) Summary() string

Summary returns OpenAPI summary.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements http server based on OpenAPI v3 specification and calls Handler to handle requests.

func NewServer

func NewServer(h Handler, opts ...ServerOption) (*Server, error)

NewServer creates new Server.

func (*Server) FindPath

func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool)

FindPath finds Route for given method and URL.

func (*Server) FindRoute

func (s *Server) FindRoute(method, path string) (Route, bool)

FindRoute finds Route for given method and path.

Note: this method does not unescape path or handle reserved characters in path properly. Use FindPath instead.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves http request as defined by OpenAPI v3 specification, calling handler that matches the path or returning not found error.

type ServerOption

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

ServerOption is server config option.

func WithErrorHandler

func WithErrorHandler(h ErrorHandler) ServerOption

WithErrorHandler specifies error handler to use.

func WithMaxMultipartMemory

func WithMaxMultipartMemory(max int64) ServerOption

WithMaxMultipartMemory specifies limit of memory for storing file parts. File parts which can't be stored in memory will be stored on disk in temporary files.

func WithMethodNotAllowed

func WithMethodNotAllowed(methodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string)) ServerOption

WithMethodNotAllowed specifies Method Not Allowed handler to use.

func WithMiddleware

func WithMiddleware(m ...Middleware) ServerOption

WithMiddleware specifies middlewares to use.

func WithNotFound

func WithNotFound(notFound http.HandlerFunc) ServerOption

WithNotFound specifies Not Found handler to use.

func WithPathPrefix

func WithPathPrefix(prefix string) ServerOption

WithPathPrefix specifies server path prefix.

type ShowPetByIdParams

type ShowPetByIdParams struct {
	// The id of the pet to retrieve.
	PetId string
}

ShowPetByIdParams is parameters of showPetById operation.

type UnimplementedHandler

type UnimplementedHandler struct{}

UnimplementedHandler is no-op Handler which returns http.ErrNotImplemented.

func (UnimplementedHandler) CreatePets

func (UnimplementedHandler) CreatePets(ctx context.Context) error

CreatePets implements createPets operation.

Create a pet.

POST /pets

func (UnimplementedHandler) ListPets

func (UnimplementedHandler) ListPets(ctx context.Context, params ListPetsParams) (r *PetsHeaders, _ error)

ListPets implements listPets operation.

List all pets.

GET /pets

func (UnimplementedHandler) NewError

func (UnimplementedHandler) NewError(ctx context.Context, err error) (r *ErrorStatusCode)

NewError creates *ErrorStatusCode from error returned by handler.

Used for common default response.

func (UnimplementedHandler) ShowPetById

func (UnimplementedHandler) ShowPetById(ctx context.Context, params ShowPetByIdParams) (r *Pet, _ error)

ShowPetById implements showPetById operation.

Info for a specific pet.

GET /pets/{petId}

Jump to

Keyboard shortcuts

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