rapi

package module
v0.8.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: BSD-3-Clause Imports: 19 Imported by: 0

README

rapi

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallOption added in v0.8.0

type CallOption interface {
	// contains filtered or unexported methods
}

func WithAdditionalRequestHeader added in v0.2.0

func WithAdditionalRequestHeader(header ...http.Header) CallOption

func WithErrOut added in v0.3.0

func WithErrOut(errOut error) CallOption

func WithForceBody added in v0.5.0

func WithForceBody(forceBody bool) CallOption

func WithMaxResponseBodySize added in v0.2.0

func WithMaxResponseBodySize(maxResponseBodySize int64) CallOption

func WithRequestHeader added in v0.2.0

func WithRequestHeader(header ...http.Header) CallOption

type Caller

type Caller struct {
	// contains filtered or unexported fields
}

Caller is the HTTP requester to do JSON requests with the given method to the given endpoint. The method and endpoint are given from Factory.

func (*Caller) Call

func (c *Caller) Call(ctx context.Context, in interface{}, opts ...CallOption) (result *Response, err error)

Call does the HTTP request with the given input and CallOption's.

type DoFunc

type DoFunc func(req *Request, send SendFunc)

type Factory added in v0.2.0

type Factory struct {
	// contains filtered or unexported fields
}

Factory is Caller factory to create new Caller's.

func NewFactory added in v0.2.0

func NewFactory(client *http.Client, u *url.URL, opts ...CallOption) (f *Factory)

NewFactory creates a new Factory.

func (*Factory) Caller added in v0.2.0

func (f *Factory) Caller(endpoint string, method string, out interface{}, opts ...CallOption) *Caller

Caller creates a new Caller with the given endpoint and method.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler implements http.Handler to process JSON requests based on pattern and registered methods. Handler is similar to http.ServeMux in terms of operation.

func NewHandler

func NewHandler(opts ...HandlerOption) (h *Handler)

NewHandler creates a new Handler by given HandlerOption's.

func (*Handler) Handle

func (h *Handler) Handle(pattern string, opts ...HandlerOption) Registrar

Handle creates a Registrar to register methods for the given pattern.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is implementation of http.Handler.

type HandlerOption

type HandlerOption interface {
	// contains filtered or unexported methods
}

func WithAllowEncoding added in v0.2.0

func WithAllowEncoding(allowEncoding bool) HandlerOption

func WithMaxRequestBodySize

func WithMaxRequestBodySize(maxRequestBodySize int64) HandlerOption

func WithMiddleware

func WithMiddleware(middleware ...MiddlewareFunc) HandlerOption

func WithOnError

func WithOnError(onError func(error, *http.Request)) HandlerOption

func WithRequestTimeout added in v0.2.0

func WithRequestTimeout(requestTimeout time.Duration) HandlerOption

func WithResponseTimeout added in v0.5.0

func WithResponseTimeout(responseTimeout time.Duration) HandlerOption

type HeaderOption added in v0.2.0

type HeaderOption struct {
	KeyVals []HeaderOptionKeyVal
	Map     map[string]string
}

func ParseHeaderOptions added in v0.2.0

func ParseHeaderOptions(directive string) (options []HeaderOption)

type HeaderOptionKeyVal added in v0.2.0

type HeaderOptionKeyVal struct {
	Key string
	Val string
}

type InvalidContentTypeError added in v0.6.0

type InvalidContentTypeError struct {
	// contains filtered or unexported fields
}

func (*InvalidContentTypeError) ContentType added in v0.6.0

func (e *InvalidContentTypeError) ContentType() string

func (*InvalidContentTypeError) Error added in v0.6.0

func (e *InvalidContentTypeError) Error() string

type MiddlewareFunc added in v0.2.0

type MiddlewareFunc func(req *Request, send SendFunc, do DoFunc)

type Registrar added in v0.8.0

type Registrar interface {
	Register(method string, in interface{}, do DoFunc, opts ...HandlerOption) Registrar
}

Registrar is method registrar and created by Handler.

type Request

type Request struct {
	*http.Request
	In interface{}
}

type RequestError added in v0.6.0

type RequestError struct {
	// contains filtered or unexported fields
}

func (*RequestError) Error added in v0.6.0

func (e *RequestError) Error() string

type Response

type Response struct {
	*http.Response
	Data []byte
	Out  interface{}
}

type SendFunc

type SendFunc func(out interface{}, code int, header ...http.Header)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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