api

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 24 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 Alias added in v1.15.0

type Alias time.Time

func (*Alias) Decode added in v1.15.0

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

Decode decodes Alias from json.

func (Alias) Encode added in v1.15.0

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

Encode encodes Alias as json.

func (Alias) MarshalJSON added in v1.15.0

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

MarshalJSON implements stdjson.Marshaler.

func (*Alias) UnmarshalJSON added in v1.15.0

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

UnmarshalJSON implements stdjson.Unmarshaler.

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) Optional added in v1.15.0

func (c *Client) Optional(ctx context.Context, params OptionalParams) (*OptionalOK, error)

Optional invokes optional operation.

GET /optional

func (*Client) Required

func (c *Client) Required(ctx context.Context, params RequiredParams) (*RequiredOK, error)

Required invokes required operation.

GET /required

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 ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type Handler

type Handler interface {
	// Optional implements optional operation.
	//
	// GET /optional
	Optional(ctx context.Context, params OptionalParams) (*OptionalOK, error)
	// Required implements required operation.
	//
	// GET /required
	Required(ctx context.Context, params RequiredParams) (*RequiredOK, error)
}

Handler handles operations described by OpenAPI v3 specification.

type Invoker

type Invoker interface {
	// Optional invokes optional operation.
	//
	// GET /optional
	Optional(ctx context.Context, params OptionalParams) (*OptionalOK, error)
	// Required invokes required operation.
	//
	// GET /required
	Required(ctx context.Context, params RequiredParams) (*RequiredOK, 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 added in v1.7.0

type OperationName = string

OperationName is the ogen operation name

const (
	OptionalOperation OperationName = "Optional"
	RequiredOperation OperationName = "Required"
)

type OptAlias added in v1.15.0

type OptAlias struct {
	Value Alias
	Set   bool
}

OptAlias is optional Alias.

func NewOptAlias added in v1.15.0

func NewOptAlias(v Alias) OptAlias

NewOptAlias returns new OptAlias with value set to v.

func (*OptAlias) Decode added in v1.15.0

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

Decode decodes Alias from json.

func (OptAlias) Encode added in v1.15.0

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

Encode encodes Alias as json.

func (OptAlias) Get added in v1.15.0

func (o OptAlias) Get() (v Alias, ok bool)

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

func (OptAlias) IsSet added in v1.15.0

func (o OptAlias) IsSet() bool

IsSet returns true if OptAlias was set.

func (OptAlias) MarshalJSON added in v1.15.0

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

MarshalJSON implements stdjson.Marshaler.

func (OptAlias) Or added in v1.15.0

func (o OptAlias) Or(d Alias) Alias

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

func (*OptAlias) Reset added in v1.15.0

func (o *OptAlias) Reset()

Reset unsets value.

func (*OptAlias) SetTo added in v1.15.0

func (o *OptAlias) SetTo(v Alias)

SetTo sets value to v.

func (*OptAlias) UnmarshalJSON added in v1.15.0

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

UnmarshalJSON implements stdjson.Unmarshaler.

type OptDate

type OptDate struct {
	Value time.Time
	Set   bool
}

OptDate is optional time.Time.

func NewOptDate

func NewOptDate(v time.Time) OptDate

NewOptDate returns new OptDate with value set to v.

func (*OptDate) Decode

func (o *OptDate) Decode(d *jx.Decoder, format func(*jx.Decoder) (time.Time, error)) error

Decode decodes time.Time from json.

func (OptDate) Encode

func (o OptDate) Encode(e *jx.Encoder, format func(*jx.Encoder, time.Time))

Encode encodes time.Time as json.

func (OptDate) Get

func (o OptDate) Get() (v time.Time, ok bool)

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

func (OptDate) IsSet

func (o OptDate) IsSet() bool

IsSet returns true if OptDate was set.

func (OptDate) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptDate) Or

func (o OptDate) Or(d time.Time) time.Time

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

func (*OptDate) Reset

func (o *OptDate) Reset()

Reset unsets value.

func (*OptDate) SetTo

func (o *OptDate) SetTo(v time.Time)

SetTo sets value to v.

func (*OptDate) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type OptDateTime

type OptDateTime struct {
	Value time.Time
	Set   bool
}

OptDateTime is optional time.Time.

func NewOptDateTime

func NewOptDateTime(v time.Time) OptDateTime

NewOptDateTime returns new OptDateTime with value set to v.

func (*OptDateTime) Decode

func (o *OptDateTime) Decode(d *jx.Decoder, format func(*jx.Decoder) (time.Time, error)) error

Decode decodes time.Time from json.

func (OptDateTime) Encode

func (o OptDateTime) Encode(e *jx.Encoder, format func(*jx.Encoder, time.Time))

Encode encodes time.Time as json.

func (OptDateTime) Get

func (o OptDateTime) Get() (v time.Time, ok bool)

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

func (OptDateTime) IsSet

func (o OptDateTime) IsSet() bool

IsSet returns true if OptDateTime was set.

func (OptDateTime) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptDateTime) Or

func (o OptDateTime) Or(d time.Time) time.Time

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

func (*OptDateTime) Reset

func (o *OptDateTime) Reset()

Reset unsets value.

func (*OptDateTime) SetTo

func (o *OptDateTime) SetTo(v time.Time)

SetTo sets value to v.

func (*OptDateTime) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type OptTime

type OptTime struct {
	Value time.Time
	Set   bool
}

OptTime is optional time.Time.

func NewOptTime

func NewOptTime(v time.Time) OptTime

NewOptTime returns new OptTime with value set to v.

func (*OptTime) Decode

func (o *OptTime) Decode(d *jx.Decoder, format func(*jx.Decoder) (time.Time, error)) error

Decode decodes time.Time from json.

func (OptTime) Encode

func (o OptTime) Encode(e *jx.Encoder, format func(*jx.Encoder, time.Time))

Encode encodes time.Time as json.

func (OptTime) Get

func (o OptTime) Get() (v time.Time, ok bool)

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

func (OptTime) IsSet

func (o OptTime) IsSet() bool

IsSet returns true if OptTime was set.

func (OptTime) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptTime) Or

func (o OptTime) Or(d time.Time) time.Time

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

func (*OptTime) Reset

func (o *OptTime) Reset()

Reset unsets value.

func (*OptTime) SetTo

func (o *OptTime) SetTo(v time.Time)

SetTo sets value to v.

func (*OptTime) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type Option

type Option interface {
	ServerOption
	ClientOption
}

Option is config option.

func WithAttributes added in v1.15.0

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 OptionalOK added in v1.15.0

type OptionalOK struct {
	Date     OptDate     `json:"date"`
	Time     OptTime     `json:"time"`
	DateTime OptDateTime `json:"dateTime"`
	Alias    OptAlias    `json:"alias"`
}

func (*OptionalOK) Decode added in v1.15.0

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

Decode decodes OptionalOK from json.

func (*OptionalOK) Encode added in v1.15.0

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

Encode implements json.Marshaler.

func (*OptionalOK) GetAlias added in v1.15.0

func (s *OptionalOK) GetAlias() OptAlias

GetAlias returns the value of Alias.

func (*OptionalOK) GetDate added in v1.15.0

func (s *OptionalOK) GetDate() OptDate

GetDate returns the value of Date.

func (*OptionalOK) GetDateTime added in v1.15.0

func (s *OptionalOK) GetDateTime() OptDateTime

GetDateTime returns the value of DateTime.

func (*OptionalOK) GetTime added in v1.15.0

func (s *OptionalOK) GetTime() OptTime

GetTime returns the value of Time.

func (*OptionalOK) MarshalJSON added in v1.15.0

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

MarshalJSON implements stdjson.Marshaler.

func (*OptionalOK) SetAlias added in v1.15.0

func (s *OptionalOK) SetAlias(val OptAlias)

SetAlias sets the value of Alias.

func (*OptionalOK) SetDate added in v1.15.0

func (s *OptionalOK) SetDate(val OptDate)

SetDate sets the value of Date.

func (*OptionalOK) SetDateTime added in v1.15.0

func (s *OptionalOK) SetDateTime(val OptDateTime)

SetDateTime sets the value of DateTime.

func (*OptionalOK) SetTime added in v1.15.0

func (s *OptionalOK) SetTime(val OptTime)

SetTime sets the value of Time.

func (*OptionalOK) UnmarshalJSON added in v1.15.0

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

UnmarshalJSON implements stdjson.Unmarshaler.

type OptionalParams added in v1.15.0

type OptionalParams struct {
	Date     OptDate     `json:",omitempty,omitzero"`
	Time     OptTime     `json:",omitempty,omitzero"`
	DateTime OptDateTime `json:",omitempty,omitzero"`
	Alias    OptAlias    `json:",omitempty,omitzero"`
}

OptionalParams is parameters of optional operation.

type RequiredOK

type RequiredOK struct {
	Date     time.Time `json:"date"`
	Time     time.Time `json:"time"`
	DateTime time.Time `json:"dateTime"`
	Alias    Alias     `json:"alias"`
}

func (*RequiredOK) Decode

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

Decode decodes RequiredOK from json.

func (*RequiredOK) Encode

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

Encode implements json.Marshaler.

func (*RequiredOK) GetAlias added in v1.15.0

func (s *RequiredOK) GetAlias() Alias

GetAlias returns the value of Alias.

func (*RequiredOK) GetDate

func (s *RequiredOK) GetDate() time.Time

GetDate returns the value of Date.

func (*RequiredOK) GetDateTime

func (s *RequiredOK) GetDateTime() time.Time

GetDateTime returns the value of DateTime.

func (*RequiredOK) GetTime

func (s *RequiredOK) GetTime() time.Time

GetTime returns the value of Time.

func (*RequiredOK) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*RequiredOK) SetAlias added in v1.15.0

func (s *RequiredOK) SetAlias(val Alias)

SetAlias sets the value of Alias.

func (*RequiredOK) SetDate

func (s *RequiredOK) SetDate(val time.Time)

SetDate sets the value of Date.

func (*RequiredOK) SetDateTime

func (s *RequiredOK) SetDateTime(val time.Time)

SetDateTime sets the value of DateTime.

func (*RequiredOK) SetTime

func (s *RequiredOK) SetTime(val time.Time)

SetTime sets the value of Time.

func (*RequiredOK) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type RequiredParams

type RequiredParams struct {
	Date     time.Time
	Time     time.Time
	DateTime time.Time
	Alias    Alias
}

RequiredParams is parameters of required operation.

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 added in v1.17.0

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 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) Optional added in v1.15.0

func (UnimplementedHandler) Optional(ctx context.Context, params OptionalParams) (r *OptionalOK, _ error)

Optional implements optional operation.

GET /optional

func (UnimplementedHandler) Required

func (UnimplementedHandler) Required(ctx context.Context, params RequiredParams) (r *RequiredOK, _ error)

Required implements required operation.

GET /required

Jump to

Keyboard shortcuts

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