api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 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) GetKeyboard

func (c *Client) GetKeyboard(ctx context.Context, params GetKeyboardParams) (*Keyboard, error)

GetKeyboard invokes getKeyboard operation.

GET /keyboard/{id}

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 GetKeyboardParams

type GetKeyboardParams struct {
	ID int64
}

GetKeyboardParams is parameters of getKeyboard operation.

type Handler

type Handler interface {
	// GetKeyboard implements getKeyboard operation.
	//
	// GET /keyboard/{id}
	GetKeyboard(ctx context.Context, params GetKeyboardParams) (*Keyboard, error)
}

Handler handles operations described by OpenAPI v3 specification.

type Keyboard

type Keyboard struct {
	ID       int64    `json:"id"`
	Name     string   `json:"name"`
	Switches Switches `json:"switches"`
	Keycaps  Keycaps  `json:"keycaps"`
	Price    int64    `json:"price"`
	Discount NilInt64 `json:"discount"`
}

Ref: #/components/schemas/Keyboard

func (*Keyboard) Decode

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

Decode decodes Keyboard from json.

func (*Keyboard) Encode

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

Encode implements json.Marshaler.

func (*Keyboard) GetDiscount

func (s *Keyboard) GetDiscount() NilInt64

GetDiscount returns the value of Discount.

func (*Keyboard) GetID

func (s *Keyboard) GetID() int64

GetID returns the value of ID.

func (*Keyboard) GetKeycaps

func (s *Keyboard) GetKeycaps() Keycaps

GetKeycaps returns the value of Keycaps.

func (*Keyboard) GetName

func (s *Keyboard) GetName() string

GetName returns the value of Name.

func (*Keyboard) GetPrice

func (s *Keyboard) GetPrice() int64

GetPrice returns the value of Price.

func (*Keyboard) GetSwitches

func (s *Keyboard) GetSwitches() Switches

GetSwitches returns the value of Switches.

func (*Keyboard) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Keyboard) SetDiscount

func (s *Keyboard) SetDiscount(val NilInt64)

SetDiscount sets the value of Discount.

func (*Keyboard) SetID

func (s *Keyboard) SetID(val int64)

SetID sets the value of ID.

func (*Keyboard) SetKeycaps

func (s *Keyboard) SetKeycaps(val Keycaps)

SetKeycaps sets the value of Keycaps.

func (*Keyboard) SetName

func (s *Keyboard) SetName(val string)

SetName sets the value of Name.

func (*Keyboard) SetPrice

func (s *Keyboard) SetPrice(val int64)

SetPrice sets the value of Price.

func (*Keyboard) SetSwitches

func (s *Keyboard) SetSwitches(val Switches)

SetSwitches sets the value of Switches.

func (*Keyboard) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Keyboard) Validate

func (s *Keyboard) Validate() error

type Keycaps

type Keycaps struct {
	ID       int64           `json:"id"`
	Name     string          `json:"name"`
	Profile  string          `json:"profile"`
	Material KeycapsMaterial `json:"material"`
}

Ref: #/components/schemas/Keycaps

func (*Keycaps) Decode

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

Decode decodes Keycaps from json.

func (*Keycaps) Encode

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

Encode implements json.Marshaler.

func (*Keycaps) GetID

func (s *Keycaps) GetID() int64

GetID returns the value of ID.

func (*Keycaps) GetMaterial

func (s *Keycaps) GetMaterial() KeycapsMaterial

GetMaterial returns the value of Material.

func (*Keycaps) GetName

func (s *Keycaps) GetName() string

GetName returns the value of Name.

func (*Keycaps) GetProfile

func (s *Keycaps) GetProfile() string

GetProfile returns the value of Profile.

func (*Keycaps) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Keycaps) SetID

func (s *Keycaps) SetID(val int64)

SetID sets the value of ID.

func (*Keycaps) SetMaterial

func (s *Keycaps) SetMaterial(val KeycapsMaterial)

SetMaterial sets the value of Material.

func (*Keycaps) SetName

func (s *Keycaps) SetName(val string)

SetName sets the value of Name.

func (*Keycaps) SetProfile

func (s *Keycaps) SetProfile(val string)

SetProfile sets the value of Profile.

func (*Keycaps) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Keycaps) Validate

func (s *Keycaps) Validate() error

type KeycapsMaterial

type KeycapsMaterial string
const (
	KeycapsMaterialABS KeycapsMaterial = "ABS"
	KeycapsMaterialPBT KeycapsMaterial = "PBT"
)

func (*KeycapsMaterial) Decode

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

Decode decodes KeycapsMaterial from json.

func (KeycapsMaterial) Encode

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

Encode encodes KeycapsMaterial as json.

func (KeycapsMaterial) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (KeycapsMaterial) MarshalText

func (s KeycapsMaterial) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*KeycapsMaterial) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*KeycapsMaterial) UnmarshalText

func (s *KeycapsMaterial) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (KeycapsMaterial) Validate

func (s KeycapsMaterial) Validate() error

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type NilInt64

type NilInt64 struct {
	Value int64
	Null  bool
}

NilInt64 is nullable int64.

func NewNilInt64

func NewNilInt64(v int64) NilInt64

NewNilInt64 returns new NilInt64 with value set to v.

func (*NilInt64) Decode

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

Decode decodes int64 from json.

func (NilInt64) Encode

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

Encode encodes int64 as json.

func (NilInt64) Get

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

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

func (NilInt64) IsNull

func (o NilInt64) IsNull() bool

IsSet returns true if value is Null.

func (NilInt64) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (NilInt64) Or

func (o NilInt64) Or(d int64) int64

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

func (*NilInt64) SetTo

func (o *NilInt64) SetTo(v int64)

SetTo sets value to v.

func (*NilInt64) SetToNull

func (o *NilInt64) SetToNull()

SetNull sets value to null.

func (*NilInt64) UnmarshalJSON

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

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 Switches

type Switches struct {
	ID         int64              `json:"id"`
	Name       string             `json:"name"`
	SwitchType SwitchesSwitchType `json:"switch_type"`
}

Ref: #/components/schemas/Switches

func (*Switches) Decode

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

Decode decodes Switches from json.

func (*Switches) Encode

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

Encode implements json.Marshaler.

func (*Switches) GetID

func (s *Switches) GetID() int64

GetID returns the value of ID.

func (*Switches) GetName

func (s *Switches) GetName() string

GetName returns the value of Name.

func (*Switches) GetSwitchType

func (s *Switches) GetSwitchType() SwitchesSwitchType

GetSwitchType returns the value of SwitchType.

func (*Switches) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Switches) SetID

func (s *Switches) SetID(val int64)

SetID sets the value of ID.

func (*Switches) SetName

func (s *Switches) SetName(val string)

SetName sets the value of Name.

func (*Switches) SetSwitchType

func (s *Switches) SetSwitchType(val SwitchesSwitchType)

SetSwitchType sets the value of SwitchType.

func (*Switches) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Switches) Validate

func (s *Switches) Validate() error

type SwitchesSwitchType

type SwitchesSwitchType string
const (
	SwitchesSwitchTypeMechanical        SwitchesSwitchType = "mechanical"
	SwitchesSwitchTypeOptical           SwitchesSwitchType = "optical"
	SwitchesSwitchTypeElectrocapacitive SwitchesSwitchType = "electrocapacitive"
)

func (*SwitchesSwitchType) Decode

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

Decode decodes SwitchesSwitchType from json.

func (SwitchesSwitchType) Encode

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

Encode encodes SwitchesSwitchType as json.

func (SwitchesSwitchType) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (SwitchesSwitchType) MarshalText

func (s SwitchesSwitchType) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*SwitchesSwitchType) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*SwitchesSwitchType) UnmarshalText

func (s *SwitchesSwitchType) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (SwitchesSwitchType) Validate

func (s SwitchesSwitchType) Validate() error

type UnimplementedHandler

type UnimplementedHandler struct{}

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

func (UnimplementedHandler) GetKeyboard

func (UnimplementedHandler) GetKeyboard(ctx context.Context, params GetKeyboardParams) (r *Keyboard, _ error)

GetKeyboard implements getKeyboard operation.

GET /keyboard/{id}

Jump to

Keyboard shortcuts

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