api

package
v0.60.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: Apache-2.0 Imports: 29 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) EventPost

func (c *Client) EventPost(ctx context.Context, request any) (any, error)

EventPost invokes POST /event operation.

POST /event

func (*Client) PhoneGet

func (c *Client) PhoneGet(ctx context.Context, request *User, params PhoneGetParams) (*User, error)

PhoneGet invokes GET /phone operation.

GET /phone

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 {
	// EventPost implements POST /event operation.
	//
	// POST /event
	EventPost(ctx context.Context, req any) (any, error)
	// PhoneGet implements GET /phone operation.
	//
	// GET /phone
	PhoneGet(ctx context.Context, req *User, params PhoneGetParams) (*User, error)
}

Handler handles operations described by OpenAPI v3 specification.

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type OptHex

type OptHex struct {
	Value int64
	Set   bool
}

OptHex is optional int64.

func NewOptHex

func NewOptHex(v int64) OptHex

NewOptHex returns new OptHex with value set to v.

func (*OptHex) Decode

func (o *OptHex) Decode(d *jx.Decoder, format func(*jx.Decoder) (int64, error)) error

Decode decodes int64 from json.

func (OptHex) Encode

func (o OptHex) Encode(e *jx.Encoder, format func(*jx.Encoder, int64))

Encode encodes int64 as json.

func (OptHex) Get

func (o OptHex) Get() (v int64, ok bool)

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

func (OptHex) IsSet

func (o OptHex) IsSet() bool

IsSet returns true if OptHex was set.

func (OptHex) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptHex) Or

func (o OptHex) Or(d int64) int64

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

func (*OptHex) Reset

func (o *OptHex) Reset()

Reset unsets value.

func (*OptHex) SetTo

func (o *OptHex) SetTo(v int64)

SetTo sets value to v.

func (*OptHex) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type OptPhone

type OptPhone struct {
	Value custom2.Phone
	Set   bool
}

OptPhone is optional custom2.Phone.

func NewOptPhone

func NewOptPhone(v custom2.Phone) OptPhone

NewOptPhone returns new OptPhone with value set to v.

func (*OptPhone) Decode

func (o *OptPhone) Decode(d *jx.Decoder, format func(*jx.Decoder) (custom2.Phone, error)) error

Decode decodes custom2.Phone from json.

func (OptPhone) Encode

func (o OptPhone) Encode(e *jx.Encoder, format func(*jx.Encoder, custom2.Phone))

Encode encodes custom2.Phone as json.

func (OptPhone) Get

func (o OptPhone) Get() (v custom2.Phone, ok bool)

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

func (OptPhone) IsSet

func (o OptPhone) IsSet() bool

IsSet returns true if OptPhone was set.

func (OptPhone) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptPhone) Or

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

func (*OptPhone) Reset

func (o *OptPhone) Reset()

Reset unsets value.

func (*OptPhone) SetTo

func (o *OptPhone) SetTo(v custom2.Phone)

SetTo sets value to v.

func (*OptPhone) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type OptRgba

type OptRgba struct {
	Value custom3.RGBA
	Set   bool
}

OptRgba is optional custom3.RGBA.

func NewOptRgba

func NewOptRgba(v custom3.RGBA) OptRgba

NewOptRgba returns new OptRgba with value set to v.

func (*OptRgba) Decode

func (o *OptRgba) Decode(d *jx.Decoder, format func(*jx.Decoder) (custom3.RGBA, error)) error

Decode decodes custom3.RGBA from json.

func (OptRgba) Encode

func (o OptRgba) Encode(e *jx.Encoder, format func(*jx.Encoder, custom3.RGBA))

Encode encodes custom3.RGBA as json.

func (OptRgba) Get

func (o OptRgba) Get() (v custom3.RGBA, ok bool)

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

func (OptRgba) IsSet

func (o OptRgba) IsSet() bool

IsSet returns true if OptRgba was set.

func (OptRgba) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptRgba) Or

func (o OptRgba) Or(d custom3.RGBA) custom3.RGBA

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

func (*OptRgba) Reset

func (o *OptRgba) Reset()

Reset unsets value.

func (*OptRgba) SetTo

func (o *OptRgba) SetTo(v custom3.RGBA)

SetTo sets value to v.

func (*OptRgba) UnmarshalJSON

func (s *OptRgba) 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 metric.NewNoopMeterProvider 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 PhoneGetParams

type PhoneGetParams struct {
	// Phone number.
	Phone custom2.Phone
	// Color.
	Color OptRgba
	// Hex.
	Hex OptHex
}

PhoneGetParams is parameters of GET /phone 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 added in v0.58.0

func (r Route) PathPattern() string

PathPattern returns OpenAPI path.

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

func (UnimplementedHandler) EventPost(ctx context.Context, req any) (r any, _ error)

EventPost implements POST /event operation.

POST /event

func (UnimplementedHandler) PhoneGet

func (UnimplementedHandler) PhoneGet(ctx context.Context, req *User, params PhoneGetParams) (r *User, _ error)

PhoneGet implements GET /phone operation.

GET /phone

type User

type User struct {
	ID              int64         `json:"id"`
	Phone           custom2.Phone `json:"phone"`
	HomePhone       OptPhone      `json:"home_phone"`
	ProfileColor    custom3.RGBA  `json:"profile_color"`
	BackgroundColor OptRgba       `json:"background_color"`
	HexColor        OptHex        `json:"hex_color"`
}

Ref: #/components/schemas/User

func (*User) Decode

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

Decode decodes User from json.

func (*User) Encode

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

Encode implements json.Marshaler.

func (*User) GetBackgroundColor

func (s *User) GetBackgroundColor() OptRgba

GetBackgroundColor returns the value of BackgroundColor.

func (*User) GetHexColor

func (s *User) GetHexColor() OptHex

GetHexColor returns the value of HexColor.

func (*User) GetHomePhone

func (s *User) GetHomePhone() OptPhone

GetHomePhone returns the value of HomePhone.

func (*User) GetID

func (s *User) GetID() int64

GetID returns the value of ID.

func (*User) GetPhone

func (s *User) GetPhone() custom2.Phone

GetPhone returns the value of Phone.

func (*User) GetProfileColor

func (s *User) GetProfileColor() custom3.RGBA

GetProfileColor returns the value of ProfileColor.

func (*User) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*User) SetBackgroundColor

func (s *User) SetBackgroundColor(val OptRgba)

SetBackgroundColor sets the value of BackgroundColor.

func (*User) SetHexColor

func (s *User) SetHexColor(val OptHex)

SetHexColor sets the value of HexColor.

func (*User) SetHomePhone

func (s *User) SetHomePhone(val OptPhone)

SetHomePhone sets the value of HomePhone.

func (*User) SetID

func (s *User) SetID(val int64)

SetID sets the value of ID.

func (*User) SetPhone

func (s *User) SetPhone(val custom2.Phone)

SetPhone sets the value of Phone.

func (*User) SetProfileColor

func (s *User) SetProfileColor(val custom3.RGBA)

SetProfileColor sets the value of ProfileColor.

func (*User) UnmarshalJSON

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