api

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MediaTypeApplicationJSON string = "application/json"
)

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) GetItemById

func (c *Client) GetItemById(ctx context.Context, params GetItemByIdParams) (*GetItemByIdOK, error)

GetItemById invokes getItemById operation.

GET /items/{id}

func (*Client) SearchItems

func (c *Client) SearchItems(ctx context.Context, params SearchItemsParams) (*SearchItemsOK, error)

SearchItems invokes searchItems operation.

GET /search

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 ErrResp

type ErrResp struct {
	Error OptString `json:"error"`
}

func (*ErrResp) Decode

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

Decode decodes ErrResp from json.

func (*ErrResp) Encode

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

Encode implements json.Marshaler.

func (*ErrResp) GetError

func (s *ErrResp) GetError() OptString

GetError returns the value of Error.

func (*ErrResp) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*ErrResp) SetError

func (s *ErrResp) SetError(val OptString)

SetError sets the value of Error.

func (*ErrResp) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type ErrRespStatusCode

type ErrRespStatusCode struct {
	StatusCode int
	Response   ErrResp
}

ErrRespStatusCode wraps ErrResp with StatusCode.

func (*ErrRespStatusCode) Error

func (s *ErrRespStatusCode) Error() string

func (*ErrRespStatusCode) GetResponse

func (s *ErrRespStatusCode) GetResponse() ErrResp

GetResponse returns the value of Response.

func (*ErrRespStatusCode) GetStatusCode

func (s *ErrRespStatusCode) GetStatusCode() int

GetStatusCode returns the value of StatusCode.

func (*ErrRespStatusCode) SetResponse

func (s *ErrRespStatusCode) SetResponse(val ErrResp)

SetResponse sets the value of Response.

func (*ErrRespStatusCode) SetStatusCode

func (s *ErrRespStatusCode) SetStatusCode(val int)

SetStatusCode sets the value of StatusCode.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type GetItemByIdID

type GetItemByIdID struct {
	// Type selects the active sum variant, switch on this field.
	Type GetItemByIdIDType
	UUID uuid.UUID
	Int  int
}

GetItemByIdID represents sum type.

func NewIntGetItemByIdID

func NewIntGetItemByIdID(v int) GetItemByIdID

NewIntGetItemByIdID returns new GetItemByIdID from int.

func NewUUIDGetItemByIdID

func NewUUIDGetItemByIdID(v uuid.UUID) GetItemByIdID

NewUUIDGetItemByIdID returns new GetItemByIdID from uuid.UUID.

func (GetItemByIdID) GetInt

func (s GetItemByIdID) GetInt() (v int, ok bool)

GetInt returns int and true boolean if GetItemByIdID is int.

func (GetItemByIdID) GetUUID

func (s GetItemByIdID) GetUUID() (v uuid.UUID, ok bool)

GetUUID returns uuid.UUID and true boolean if GetItemByIdID is uuid.UUID.

func (GetItemByIdID) IsInt

func (s GetItemByIdID) IsInt() bool

IsInt reports whether GetItemByIdID is int.

func (GetItemByIdID) IsUUID

func (s GetItemByIdID) IsUUID() bool

IsUUID reports whether GetItemByIdID is uuid.UUID.

func (*GetItemByIdID) SetInt

func (s *GetItemByIdID) SetInt(v int)

SetInt sets GetItemByIdID to int.

func (*GetItemByIdID) SetUUID

func (s *GetItemByIdID) SetUUID(v uuid.UUID)

SetUUID sets GetItemByIdID to uuid.UUID.

type GetItemByIdIDType

type GetItemByIdIDType string

GetItemByIdIDType is oneOf type of GetItemByIdID.

const (
	UUIDGetItemByIdID GetItemByIdIDType = "uuid.UUID"
	IntGetItemByIdID  GetItemByIdIDType = "int"
)

Possible values for GetItemByIdIDType.

type GetItemByIdOK

type GetItemByIdOK struct {
	ID      OptString `json:"id"`
	Message OptString `json:"message"`
}

func (*GetItemByIdOK) Decode

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

Decode decodes GetItemByIdOK from json.

func (*GetItemByIdOK) Encode

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

Encode implements json.Marshaler.

func (*GetItemByIdOK) GetID

func (s *GetItemByIdOK) GetID() OptString

GetID returns the value of ID.

func (*GetItemByIdOK) GetMessage

func (s *GetItemByIdOK) GetMessage() OptString

GetMessage returns the value of Message.

func (*GetItemByIdOK) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*GetItemByIdOK) SetID

func (s *GetItemByIdOK) SetID(val OptString)

SetID sets the value of ID.

func (*GetItemByIdOK) SetMessage

func (s *GetItemByIdOK) SetMessage(val OptString)

SetMessage sets the value of Message.

func (*GetItemByIdOK) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type GetItemByIdParams

type GetItemByIdParams struct {
	// Item ID - can be UUID or integer.
	ID GetItemByIdID
}

GetItemByIdParams is parameters of getItemById operation.

type Handler

type Handler interface {
	// GetItemById implements getItemById operation.
	//
	// GET /items/{id}
	GetItemById(ctx context.Context, params GetItemByIdParams) (*GetItemByIdOK, error)
	// SearchItems implements searchItems operation.
	//
	// GET /search
	SearchItems(ctx context.Context, params SearchItemsParams) (*SearchItemsOK, error)
	// NewError creates *ErrRespStatusCode from error returned by handler.
	//
	// Used for common default response.
	NewError(ctx context.Context, err error) *ErrRespStatusCode
}

Handler handles operations described by OpenAPI v3 specification.

type Invoker

type Invoker interface {
	// GetItemById invokes getItemById operation.
	//
	// GET /items/{id}
	GetItemById(ctx context.Context, params GetItemByIdParams) (*GetItemByIdOK, error)
	// SearchItems invokes searchItems operation.
	//
	// GET /search
	SearchItems(ctx context.Context, params SearchItemsParams) (*SearchItemsOK, error)
}

Invoker invokes operations described by OpenAPI v3 specification.

type Labeler

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

Labeler is used to allow adding custom attributes to the server request metrics.

func LabelerFromContext

func LabelerFromContext(ctx context.Context) (*Labeler, bool)

LabelerFromContext retrieves the Labeler from the provided context, if present.

If no Labeler was found in the provided context a new, empty Labeler is returned and the second return value is false. In this case it is safe to use the Labeler but any attributes added to it will not be used.

func (*Labeler) Add

func (l *Labeler) Add(attrs ...attribute.KeyValue)

Add attributes to the Labeler.

func (*Labeler) AttributeSet

func (l *Labeler) AttributeSet() attribute.Set

AttributeSet returns the attributes added to the Labeler as an attribute.Set.

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type OperationName

type OperationName = string

OperationName is the ogen operation name

const (
	GetItemByIdOperation OperationName = "GetItemById"
	SearchItemsOperation OperationName = "SearchItems"
)

type OptSearchItemsFilter

type OptSearchItemsFilter struct {
	Value SearchItemsFilter
	Set   bool
}

OptSearchItemsFilter is optional SearchItemsFilter.

func NewOptSearchItemsFilter

func NewOptSearchItemsFilter(v SearchItemsFilter) OptSearchItemsFilter

NewOptSearchItemsFilter returns new OptSearchItemsFilter with value set to v.

func (OptSearchItemsFilter) Get

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

func (OptSearchItemsFilter) IsSet

func (o OptSearchItemsFilter) IsSet() bool

IsSet returns true if OptSearchItemsFilter was set.

func (OptSearchItemsFilter) Or

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

func (*OptSearchItemsFilter) Reset

func (o *OptSearchItemsFilter) Reset()

Reset unsets value.

func (*OptSearchItemsFilter) SetTo

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) 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 WithAttributes

func WithAttributes(attributes ...attribute.KeyValue) Option

WithAttributes specifies default otel attributes.

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) OperationGroup

func (r Route) OperationGroup() string

OperationGroup returns the x-ogen-operation-group value.

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 SearchItemsFilter

type SearchItemsFilter struct {
	// Type selects the active sum variant, switch on this field.
	Type   SearchItemsFilterType
	String string
	Int    int
}

SearchItemsFilter represents sum type.

func NewIntSearchItemsFilter

func NewIntSearchItemsFilter(v int) SearchItemsFilter

NewIntSearchItemsFilter returns new SearchItemsFilter from int.

func NewStringSearchItemsFilter

func NewStringSearchItemsFilter(v string) SearchItemsFilter

NewStringSearchItemsFilter returns new SearchItemsFilter from string.

func (SearchItemsFilter) GetInt

func (s SearchItemsFilter) GetInt() (v int, ok bool)

GetInt returns int and true boolean if SearchItemsFilter is int.

func (SearchItemsFilter) GetString

func (s SearchItemsFilter) GetString() (v string, ok bool)

GetString returns string and true boolean if SearchItemsFilter is string.

func (SearchItemsFilter) IsInt

func (s SearchItemsFilter) IsInt() bool

IsInt reports whether SearchItemsFilter is int.

func (SearchItemsFilter) IsString

func (s SearchItemsFilter) IsString() bool

IsString reports whether SearchItemsFilter is string.

func (*SearchItemsFilter) SetInt

func (s *SearchItemsFilter) SetInt(v int)

SetInt sets SearchItemsFilter to int.

func (*SearchItemsFilter) SetString

func (s *SearchItemsFilter) SetString(v string)

SetString sets SearchItemsFilter to string.

type SearchItemsFilterType

type SearchItemsFilterType string

SearchItemsFilterType is oneOf type of SearchItemsFilter.

const (
	StringSearchItemsFilter SearchItemsFilterType = "string"
	IntSearchItemsFilter    SearchItemsFilterType = "int"
)

Possible values for SearchItemsFilterType.

type SearchItemsOK

type SearchItemsOK struct {
	Results []string `json:"results"`
}

func (*SearchItemsOK) Decode

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

Decode decodes SearchItemsOK from json.

func (*SearchItemsOK) Encode

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

Encode implements json.Marshaler.

func (*SearchItemsOK) GetResults

func (s *SearchItemsOK) GetResults() []string

GetResults returns the value of Results.

func (*SearchItemsOK) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*SearchItemsOK) SetResults

func (s *SearchItemsOK) SetResults(val []string)

SetResults sets the value of Results.

func (*SearchItemsOK) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type SearchItemsParams

type SearchItemsParams struct {
	// Filter value - can be string or number.
	Filter OptSearchItemsFilter `json:",omitempty,omitzero"`
}

SearchItemsParams is parameters of searchItems operation.

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 UnimplementedHandler

type UnimplementedHandler struct{}

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

func (UnimplementedHandler) GetItemById

func (UnimplementedHandler) GetItemById(ctx context.Context, params GetItemByIdParams) (r *GetItemByIdOK, _ error)

GetItemById implements getItemById operation.

GET /items/{id}

func (UnimplementedHandler) NewError

NewError creates *ErrRespStatusCode from error returned by handler.

Used for common default response.

func (UnimplementedHandler) SearchItems

func (UnimplementedHandler) SearchItems(ctx context.Context, params SearchItemsParams) (r *SearchItemsOK, _ error)

SearchItems implements searchItems operation.

GET /search

Jump to

Keyboard shortcuts

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