api

package
v0.0.0-...-8ab7e0f Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 28 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) CreateTodo

func (c *Client) CreateTodo(ctx context.Context, request *CreateTodoRequest) (*Todo, error)

CreateTodo invokes createTodo operation.

Create a new TODO item.

POST /todos

func (*Client) DeleteTodo

func (c *Client) DeleteTodo(ctx context.Context, params DeleteTodoParams) error

DeleteTodo invokes deleteTodo operation.

Delete a specific TODO item.

DELETE /todos/{id}

func (*Client) GetTodo

func (c *Client) GetTodo(ctx context.Context, params GetTodoParams) (*Todo, error)

GetTodo invokes getTodo operation.

Get a specific TODO item.

GET /todos/{id}

func (*Client) ListTodos

func (c *Client) ListTodos(ctx context.Context) ([]Todo, error)

ListTodos invokes listTodos operation.

Get all TODO items.

GET /todos

func (*Client) UpdateTodo

func (c *Client) UpdateTodo(ctx context.Context, request *UpdateTodoRequest, params UpdateTodoParams) (*Todo, error)

UpdateTodo invokes updateTodo operation.

Update a specific TODO item.

PUT /todos/{id}

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 CreateTodoRequest

type CreateTodoRequest struct {
	// The title of the TODO item.
	Title string `json:"title"`
}

Ref: #/components/schemas/CreateTodoRequest

func (*CreateTodoRequest) Decode

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

Decode decodes CreateTodoRequest from json.

func (*CreateTodoRequest) Encode

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

Encode implements json.Marshaler.

func (*CreateTodoRequest) GetTitle

func (s *CreateTodoRequest) GetTitle() string

GetTitle returns the value of Title.

func (*CreateTodoRequest) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*CreateTodoRequest) SetTitle

func (s *CreateTodoRequest) SetTitle(val string)

SetTitle sets the value of Title.

func (*CreateTodoRequest) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type DeleteTodoNoContent

type DeleteTodoNoContent struct{}

DeleteTodoNoContent is response for DeleteTodo operation.

type DeleteTodoParams

type DeleteTodoParams struct {
	ID string
}

DeleteTodoParams is parameters of deleteTodo operation.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type GetTodoParams

type GetTodoParams struct {
	ID string
}

GetTodoParams is parameters of getTodo operation.

type Handler

type Handler interface {
	// CreateTodo implements createTodo operation.
	//
	// Create a new TODO item.
	//
	// POST /todos
	CreateTodo(ctx context.Context, req *CreateTodoRequest) (*Todo, error)
	// DeleteTodo implements deleteTodo operation.
	//
	// Delete a specific TODO item.
	//
	// DELETE /todos/{id}
	DeleteTodo(ctx context.Context, params DeleteTodoParams) error
	// GetTodo implements getTodo operation.
	//
	// Get a specific TODO item.
	//
	// GET /todos/{id}
	GetTodo(ctx context.Context, params GetTodoParams) (*Todo, error)
	// ListTodos implements listTodos operation.
	//
	// Get all TODO items.
	//
	// GET /todos
	ListTodos(ctx context.Context) ([]Todo, error)
	// UpdateTodo implements updateTodo operation.
	//
	// Update a specific TODO item.
	//
	// PUT /todos/{id}
	UpdateTodo(ctx context.Context, req *UpdateTodoRequest, params UpdateTodoParams) (*Todo, error)
}

Handler handles operations described by OpenAPI v3 specification.

type Invoker

type Invoker interface {
	// CreateTodo invokes createTodo operation.
	//
	// Create a new TODO item.
	//
	// POST /todos
	CreateTodo(ctx context.Context, request *CreateTodoRequest) (*Todo, error)
	// DeleteTodo invokes deleteTodo operation.
	//
	// Delete a specific TODO item.
	//
	// DELETE /todos/{id}
	DeleteTodo(ctx context.Context, params DeleteTodoParams) error
	// GetTodo invokes getTodo operation.
	//
	// Get a specific TODO item.
	//
	// GET /todos/{id}
	GetTodo(ctx context.Context, params GetTodoParams) (*Todo, error)
	// ListTodos invokes listTodos operation.
	//
	// Get all TODO items.
	//
	// GET /todos
	ListTodos(ctx context.Context) ([]Todo, error)
	// UpdateTodo invokes updateTodo operation.
	//
	// Update a specific TODO item.
	//
	// PUT /todos/{id}
	UpdateTodo(ctx context.Context, request *UpdateTodoRequest, params UpdateTodoParams) (*Todo, error)
}

Invoker invokes operations described by OpenAPI v3 specification.

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

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 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 Todo

type Todo struct {
	// The ID of the TODO item.
	ID uuid.UUID `json:"id"`
	// The title of the TODO item.
	Title string `json:"title"`
	// Whether the TODO item is completed or not.
	Completed bool `json:"completed"`
	// The date and time when the TODO item was created.
	CreatedAt time.Time `json:"created_at"`
	// The date and time when the TODO item was updated.
	UpdatedAt time.Time `json:"updated_at"`
}

Ref: #/components/schemas/Todo

func (*Todo) Decode

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

Decode decodes Todo from json.

func (*Todo) Encode

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

Encode implements json.Marshaler.

func (*Todo) GetCompleted

func (s *Todo) GetCompleted() bool

GetCompleted returns the value of Completed.

func (*Todo) GetCreatedAt

func (s *Todo) GetCreatedAt() time.Time

GetCreatedAt returns the value of CreatedAt.

func (*Todo) GetID

func (s *Todo) GetID() uuid.UUID

GetID returns the value of ID.

func (*Todo) GetTitle

func (s *Todo) GetTitle() string

GetTitle returns the value of Title.

func (*Todo) GetUpdatedAt

func (s *Todo) GetUpdatedAt() time.Time

GetUpdatedAt returns the value of UpdatedAt.

func (*Todo) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Todo) SetCompleted

func (s *Todo) SetCompleted(val bool)

SetCompleted sets the value of Completed.

func (*Todo) SetCreatedAt

func (s *Todo) SetCreatedAt(val time.Time)

SetCreatedAt sets the value of CreatedAt.

func (*Todo) SetID

func (s *Todo) SetID(val uuid.UUID)

SetID sets the value of ID.

func (*Todo) SetTitle

func (s *Todo) SetTitle(val string)

SetTitle sets the value of Title.

func (*Todo) SetUpdatedAt

func (s *Todo) SetUpdatedAt(val time.Time)

SetUpdatedAt sets the value of UpdatedAt.

func (*Todo) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type UnimplementedHandler

type UnimplementedHandler struct{}

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

func (UnimplementedHandler) CreateTodo

func (UnimplementedHandler) CreateTodo(ctx context.Context, req *CreateTodoRequest) (r *Todo, _ error)

CreateTodo implements createTodo operation.

Create a new TODO item.

POST /todos

func (UnimplementedHandler) DeleteTodo

func (UnimplementedHandler) DeleteTodo(ctx context.Context, params DeleteTodoParams) error

DeleteTodo implements deleteTodo operation.

Delete a specific TODO item.

DELETE /todos/{id}

func (UnimplementedHandler) GetTodo

func (UnimplementedHandler) GetTodo(ctx context.Context, params GetTodoParams) (r *Todo, _ error)

GetTodo implements getTodo operation.

Get a specific TODO item.

GET /todos/{id}

func (UnimplementedHandler) ListTodos

func (UnimplementedHandler) ListTodos(ctx context.Context) (r []Todo, _ error)

ListTodos implements listTodos operation.

Get all TODO items.

GET /todos

func (UnimplementedHandler) UpdateTodo

func (UnimplementedHandler) UpdateTodo(ctx context.Context, req *UpdateTodoRequest, params UpdateTodoParams) (r *Todo, _ error)

UpdateTodo implements updateTodo operation.

Update a specific TODO item.

PUT /todos/{id}

type UpdateTodoParams

type UpdateTodoParams struct {
	ID string
}

UpdateTodoParams is parameters of updateTodo operation.

type UpdateTodoRequest

type UpdateTodoRequest struct {
	// The title of the TODO item.
	Title string `json:"title"`
	// Whether the TODO item is completed or not.
	Completed bool `json:"completed"`
}

Ref: #/components/schemas/UpdateTodoRequest

func (*UpdateTodoRequest) Decode

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

Decode decodes UpdateTodoRequest from json.

func (*UpdateTodoRequest) Encode

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

Encode implements json.Marshaler.

func (*UpdateTodoRequest) GetCompleted

func (s *UpdateTodoRequest) GetCompleted() bool

GetCompleted returns the value of Completed.

func (*UpdateTodoRequest) GetTitle

func (s *UpdateTodoRequest) GetTitle() string

GetTitle returns the value of Title.

func (*UpdateTodoRequest) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*UpdateTodoRequest) SetCompleted

func (s *UpdateTodoRequest) SetCompleted(val bool)

SetCompleted sets the value of Completed.

func (*UpdateTodoRequest) SetTitle

func (s *UpdateTodoRequest) SetTitle(val string)

SetTitle sets the value of Title.

func (*UpdateTodoRequest) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

Jump to

Keyboard shortcuts

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