api

package
v0.0.0-...-b934907 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 27 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) GetError

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

GetError invokes get-error operation.

Responds with an error.

GET /error

func (*Client) Greeting

func (c *Client) Greeting(ctx context.Context, params GreetingParams) (*GetGreetingOutputBody, error)

Greeting invokes greeting operation.

Responds with a greeting.

GET /greeting/{name}

func (*Client) PostReview

func (c *Client) PostReview(ctx context.Context, request *PostReviewInputBody) error

PostReview invokes post-review operation.

Post a review to be saved.

POST /reviews

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 Error

type Error struct {
	// A short, human-readable summary of the problem type. This value should not change between
	// occurrences of the error.
	Title string `json:"title"`
	// A human-readable explanation specific to this occurrence of the problem.
	Details OptString `json:"details"`
	// Optional map of properties.
	Properties OptNilErrorProperties `json:"properties"`
}

An API error. 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) GetDetails

func (s *Error) GetDetails() OptString

GetDetails returns the value of Details.

func (*Error) GetProperties

func (s *Error) GetProperties() OptNilErrorProperties

GetProperties returns the value of Properties.

func (*Error) GetTitle

func (s *Error) GetTitle() string

GetTitle returns the value of Title.

func (*Error) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Error) SetDetails

func (s *Error) SetDetails(val OptString)

SetDetails sets the value of Details.

func (*Error) SetProperties

func (s *Error) SetProperties(val OptNilErrorProperties)

SetProperties sets the value of Properties.

func (*Error) SetTitle

func (s *Error) SetTitle(val string)

SetTitle sets the value of Title.

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 ErrorProperties

type ErrorProperties map[string]jx.Raw

Optional map of properties.

func (*ErrorProperties) Decode

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

Decode decodes ErrorProperties from json.

func (ErrorProperties) Encode

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

Encode implements json.Marshaler.

func (ErrorProperties) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*ErrorProperties) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

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 GetErrorOK

type GetErrorOK struct{}

GetErrorOK is response for GetError operation.

type GetGreetingOutputBody

type GetGreetingOutputBody struct {
	// Greeting message.
	Message string `json:"message"`
}

Ref: #/components/schemas/GetGreetingOutputBody

func (*GetGreetingOutputBody) Decode

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

Decode decodes GetGreetingOutputBody from json.

func (*GetGreetingOutputBody) Encode

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

Encode implements json.Marshaler.

func (*GetGreetingOutputBody) GetMessage

func (s *GetGreetingOutputBody) GetMessage() string

GetMessage returns the value of Message.

func (*GetGreetingOutputBody) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*GetGreetingOutputBody) SetMessage

func (s *GetGreetingOutputBody) SetMessage(val string)

SetMessage sets the value of Message.

func (*GetGreetingOutputBody) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type GreetingParams

type GreetingParams struct {
	// Name to greet.
	Name string
}

GreetingParams is parameters of greeting operation.

type Handler

type Handler interface {
	// GetError implements get-error operation.
	//
	// Responds with an error.
	//
	// GET /error
	GetError(ctx context.Context) error
	// Greeting implements greeting operation.
	//
	// Responds with a greeting.
	//
	// GET /greeting/{name}
	Greeting(ctx context.Context, params GreetingParams) (*GetGreetingOutputBody, error)
	// PostReview implements post-review operation.
	//
	// Post a review to be saved.
	//
	// POST /reviews
	PostReview(ctx context.Context, req *PostReviewInputBody) 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 {
	// GetError invokes get-error operation.
	//
	// Responds with an error.
	//
	// GET /error
	GetError(ctx context.Context) error
	// Greeting invokes greeting operation.
	//
	// Responds with a greeting.
	//
	// GET /greeting/{name}
	Greeting(ctx context.Context, params GreetingParams) (*GetGreetingOutputBody, error)
	// PostReview invokes post-review operation.
	//
	// Post a review to be saved.
	//
	// POST /reviews
	PostReview(ctx context.Context, request *PostReviewInputBody) 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 OptNilErrorProperties

type OptNilErrorProperties struct {
	Value ErrorProperties
	Set   bool
	Null  bool
}

OptNilErrorProperties is optional nullable ErrorProperties.

func NewOptNilErrorProperties

func NewOptNilErrorProperties(v ErrorProperties) OptNilErrorProperties

NewOptNilErrorProperties returns new OptNilErrorProperties with value set to v.

func (*OptNilErrorProperties) Decode

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

Decode decodes ErrorProperties from json.

func (OptNilErrorProperties) Encode

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

Encode encodes ErrorProperties as json.

func (OptNilErrorProperties) Get

func (o OptNilErrorProperties) Get() (v ErrorProperties, ok bool)

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

func (OptNilErrorProperties) IsNull

func (o OptNilErrorProperties) IsNull() bool

IsSet returns true if value is Null.

func (OptNilErrorProperties) IsSet

func (o OptNilErrorProperties) IsSet() bool

IsSet returns true if OptNilErrorProperties was set.

func (OptNilErrorProperties) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptNilErrorProperties) Or

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

func (*OptNilErrorProperties) Reset

func (o *OptNilErrorProperties) Reset()

Reset unsets value.

func (*OptNilErrorProperties) SetTo

SetTo sets value to v.

func (*OptNilErrorProperties) SetToNull

func (o *OptNilErrorProperties) SetToNull()

SetNull sets value to null.

func (*OptNilErrorProperties) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

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

type PostReviewCreated struct{}

PostReviewCreated is response for PostReview operation.

type PostReviewInputBody

type PostReviewInputBody struct {
	// Author of the review.
	Author string `json:"author"`
	// Review message.
	Message OptString `json:"message"`
	// Rating from 1 to 5.
	Rating int64 `json:"rating"`
}

Ref: #/components/schemas/PostReviewInputBody

func (*PostReviewInputBody) Decode

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

Decode decodes PostReviewInputBody from json.

func (*PostReviewInputBody) Encode

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

Encode implements json.Marshaler.

func (*PostReviewInputBody) GetAuthor

func (s *PostReviewInputBody) GetAuthor() string

GetAuthor returns the value of Author.

func (*PostReviewInputBody) GetMessage

func (s *PostReviewInputBody) GetMessage() OptString

GetMessage returns the value of Message.

func (*PostReviewInputBody) GetRating

func (s *PostReviewInputBody) GetRating() int64

GetRating returns the value of Rating.

func (*PostReviewInputBody) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*PostReviewInputBody) SetAuthor

func (s *PostReviewInputBody) SetAuthor(val string)

SetAuthor sets the value of Author.

func (*PostReviewInputBody) SetMessage

func (s *PostReviewInputBody) SetMessage(val OptString)

SetMessage sets the value of Message.

func (*PostReviewInputBody) SetRating

func (s *PostReviewInputBody) SetRating(val int64)

SetRating sets the value of Rating.

func (*PostReviewInputBody) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*PostReviewInputBody) Validate

func (s *PostReviewInputBody) 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 UnimplementedHandler

type UnimplementedHandler struct{}

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

func (UnimplementedHandler) GetError

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

GetError implements get-error operation.

Responds with an error.

GET /error

func (UnimplementedHandler) Greeting

Greeting implements greeting operation.

Responds with a greeting.

GET /greeting/{name}

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

PostReview implements post-review operation.

Post a review to be saved.

POST /reviews

Jump to

Keyboard shortcuts

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