api

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 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 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) Default

func (c *Client) Default(ctx context.Context, params DefaultParams) (*DefaultOK, error)

Default invokes default 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 DefaultOK

type DefaultOK struct {
	Date     OptDate     `json:"date"`
	Time     OptTime     `json:"time"`
	DateTime OptDateTime `json:"dateTime"`
}

func (*DefaultOK) Decode

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

Decode decodes DefaultOK from json.

func (*DefaultOK) Encode

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

Encode implements json.Marshaler.

func (*DefaultOK) GetDate

func (s *DefaultOK) GetDate() OptDate

GetDate returns the value of Date.

func (*DefaultOK) GetDateTime

func (s *DefaultOK) GetDateTime() OptDateTime

GetDateTime returns the value of DateTime.

func (*DefaultOK) GetTime

func (s *DefaultOK) GetTime() OptTime

GetTime returns the value of Time.

func (*DefaultOK) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*DefaultOK) SetDate

func (s *DefaultOK) SetDate(val OptDate)

SetDate sets the value of Date.

func (*DefaultOK) SetDateTime

func (s *DefaultOK) SetDateTime(val OptDateTime)

SetDateTime sets the value of DateTime.

func (*DefaultOK) SetTime

func (s *DefaultOK) SetTime(val OptTime)

SetTime sets the value of Time.

func (*DefaultOK) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type DefaultParams

type DefaultParams struct {
	Date     OptDate
	Time     OptTime
	DateTime OptDateTime
}

DefaultParams is parameters of default operation.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type Handler

type Handler interface {
	// Default implements default operation.
	//
	// GET /optional
	Default(ctx context.Context, params DefaultParams) (*DefaultOK, 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 {
	// Default invokes default operation.
	//
	// GET /optional
	Default(ctx context.Context, params DefaultParams) (*DefaultOK, 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 (
	DefaultOperation  OperationName = "Default"
	RequiredOperation OperationName = "Required"
)

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

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

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

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

func (UnimplementedHandler) Default(ctx context.Context, params DefaultParams) (r *DefaultOK, _ error)

Default implements default 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