Documentation
¶
Index ¶
- Constants
- type Error
- type Header
- type OnConnectHandler
- type Option
- func DumpTo(w io.Writer) Option
- func Name(name string) Option
- func Secure() Option
- func SkipTLSVerify() Option
- func WithDialTimeout(timeout time.Duration) Option
- func WithLogger(l kit.Logger) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithTracePropagator(tp kit.TracePropagator) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type RESTCtx
- func (hc *RESTCtx) AutoRun(ctx context.Context, route string, enc kit.Encoding, m kit.Message) *RESTCtx
- func (hc *RESTCtx) CopyBody(dst []byte) []byte
- func (hc *RESTCtx) DefaultResponseHandler(h RESTResponseHandler) *RESTCtx
- func (hc *RESTCtx) DumpRequest() string
- func (hc *RESTCtx) DumpRequestTo(w io.Writer) *RESTCtx
- func (hc *RESTCtx) DumpResponse() string
- func (hc *RESTCtx) DumpResponseTo(w io.Writer) *RESTCtx
- func (hc *RESTCtx) Err() *Error
- func (hc *RESTCtx) Error() error
- func (hc *RESTCtx) GET(path string) *RESTCtx
- func (hc *RESTCtx) GetBody() []byte
- func (hc *RESTCtx) GetHeader(key string) string
- func (hc *RESTCtx) OPTIONS(path string) *RESTCtx
- func (hc *RESTCtx) PATCH(path string) *RESTCtx
- func (hc *RESTCtx) POST(path string) *RESTCtx
- func (hc *RESTCtx) PUT(path string) *RESTCtx
- func (hc *RESTCtx) Release()
- func (hc *RESTCtx) Run(ctx context.Context) *RESTCtx
- func (hc *RESTCtx) SetBody(body []byte) *RESTCtx
- func (hc *RESTCtx) SetHeader(key, value string) *RESTCtx
- func (hc *RESTCtx) SetMethod(method string) *RESTCtx
- func (hc *RESTCtx) SetPath(path string) *RESTCtx
- func (hc *RESTCtx) SetQuery(key, value string) *RESTCtx
- func (hc *RESTCtx) SetResponseHandler(statusCode int, h RESTResponseHandler) *RESTCtx
- func (hc *RESTCtx) StatusCode() int
- type RESTOption
- type RESTPreflightHandler
- type RESTResponse
- type RESTResponseHandler
- type RPCContainerHandler
- type RPCMessageHandler
- type RPCPreflightHandler
- type Stub
- type WebsocketCtx
- func (wCtx *WebsocketCtx) BinaryMessage(ctx context.Context, predicate string, req, res kit.Message, ...) error
- func (wCtx *WebsocketCtx) Connect(ctx context.Context, path string) error
- func (wCtx *WebsocketCtx) Disconnect() error
- func (wCtx *WebsocketCtx) Do(ctx context.Context, req WebsocketRequest) error
- func (wCtx *WebsocketCtx) TextMessage(ctx context.Context, predicate string, req, res kit.Message, ...) error
- type WebsocketOption
- func WithAutoReconnect(b bool) WebsocketOption
- func WithCustomDialerBuilder(b func() *websocket.Dialer) WebsocketOption
- func WithCustomRPC(in kit.IncomingRPCFactory, out kit.OutgoingRPCFactory) WebsocketOption
- func WithDefaultHandler(h RPCContainerHandler) WebsocketOption
- func WithHandler(predicate string, h RPCContainerHandler) WebsocketOption
- func WithOnConnectHandler(f OnConnectHandler) WebsocketOption
- func WithPingTime(t time.Duration) WebsocketOption
- func WithPredicateKey(key string) WebsocketOption
- func WithPreflightRPC(h ...RPCPreflightHandler) WebsocketOption
- func WithUpgradeHeader(key string, values ...string) WebsocketOption
- type WebsocketRequest
Constants ¶
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. TextMessage = 1 // BinaryMessage denotes a binary data message. BinaryMessage = 2 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OnConnectHandler ¶
type OnConnectHandler func(ctx *WebsocketCtx)
type Option ¶
type Option func(cfg *config)
func SkipTLSVerify ¶
func SkipTLSVerify() Option
func WithDialTimeout ¶
func WithLogger ¶
func WithReadTimeout ¶
func WithTracePropagator ¶ added in v0.9.8
func WithTracePropagator(tp kit.TracePropagator) Option
func WithWriteTimeout ¶
type RESTCtx ¶
type RESTCtx struct {
// contains filtered or unexported fields
}
func (*RESTCtx) AutoRun ¶
func (hc *RESTCtx) AutoRun( ctx context.Context, route string, enc kit.Encoding, m kit.Message, ) *RESTCtx
AutoRun is a helper method, which fills the request based on the input arguments. It checks the route which is a path pattern, and fills the dynamic url params based on the `m`'s `tag` keys. Example:
type Request struct { ID int64 `json:"id"` Name string `json:"name"` }
AutoRun(
context.Background(), "/something/:id/:name", kit.JSON, &Request{ID: 10, Name: "customName"},
)
Is equivalent to:
SetPath("/something/10/customName"). Run(context.Background())
func (*RESTCtx) CopyBody ¶
CopyBody copies the body to `dst`. It creates a new slice and returns it if dst is nil.
func (*RESTCtx) DefaultResponseHandler ¶
func (hc *RESTCtx) DefaultResponseHandler(h RESTResponseHandler) *RESTCtx
func (*RESTCtx) DumpRequest ¶
func (*RESTCtx) DumpRequestTo ¶
DumpRequestTo accepts a writer and will write the request dump to it when Run is executed.
Please refer to DumpResponseTo
func (*RESTCtx) DumpResponse ¶
func (*RESTCtx) DumpResponseTo ¶
DumpResponseTo accepts a writer and will write the response dump to it when Run is executed. Example:
httpCtx := s.REST(). DumpRequestTo(os.Stdout). DumpResponseTo(os.Stdout). GET("https//google.com"). Run(ctx) defer httpCtx.Release()
**YOU MUST NOT USE httpCtx after httpCtx.Release() is called.**
func (*RESTCtx) GetBody ¶
GetBody returns the body, but please note that the returned slice is only valid until Release is called. If you need to use the body after releasing RESTCtx then use CopyBody method.
func (*RESTCtx) Release ¶
func (hc *RESTCtx) Release()
Release frees the allocates internal resources to be re-used. You MUST NOT refer to any method of this object after calling this method, if you call any method after Release has been called, the result is unpredictable.
func (*RESTCtx) SetResponseHandler ¶
func (hc *RESTCtx) SetResponseHandler(statusCode int, h RESTResponseHandler) *RESTCtx
func (*RESTCtx) StatusCode ¶
StatusCode returns the status code of the response
type RESTOption ¶
type RESTOption func(cfg *restConfig)
func WithPreflightREST ¶
func WithPreflightREST(h ...RESTPreflightHandler) RESTOption
WithPreflightREST register one or many handlers to run in sequence before actually making requests.
type RESTPreflightHandler ¶
type RESTResponse ¶
type RESTResponseHandler ¶
type RESTResponseHandler func(ctx context.Context, r RESTResponse) *Error
type RPCContainerHandler ¶
type RPCContainerHandler func(ctx context.Context, c kit.IncomingRPCContainer)
type RPCMessageHandler ¶
type RPCPreflightHandler ¶ added in v0.9.5
type RPCPreflightHandler func(req *WebsocketRequest)
type Stub ¶
type Stub struct {
// contains filtered or unexported fields
}
func (*Stub) REST ¶
func (s *Stub) REST(opt ...RESTOption) *RESTCtx
func (*Stub) Websocket ¶
func (s *Stub) Websocket(opts ...WebsocketOption) *WebsocketCtx
type WebsocketCtx ¶
type WebsocketCtx struct {
// contains filtered or unexported fields
}
func (*WebsocketCtx) BinaryMessage ¶
func (wCtx *WebsocketCtx) BinaryMessage( ctx context.Context, predicate string, req, res kit.Message, cb RPCMessageHandler, ) error
func (*WebsocketCtx) Connect ¶
func (wCtx *WebsocketCtx) Connect(ctx context.Context, path string) error
func (*WebsocketCtx) Disconnect ¶
func (wCtx *WebsocketCtx) Disconnect() error
func (*WebsocketCtx) Do ¶ added in v0.9.2
func (wCtx *WebsocketCtx) Do(ctx context.Context, req WebsocketRequest) error
func (*WebsocketCtx) TextMessage ¶
func (wCtx *WebsocketCtx) TextMessage( ctx context.Context, predicate string, req, res kit.Message, cb RPCMessageHandler, ) error
type WebsocketOption ¶
type WebsocketOption func(cfg *wsConfig)
func WithAutoReconnect ¶
func WithAutoReconnect(b bool) WebsocketOption
func WithCustomDialerBuilder ¶
func WithCustomDialerBuilder(b func() *websocket.Dialer) WebsocketOption
func WithCustomRPC ¶
func WithCustomRPC(in kit.IncomingRPCFactory, out kit.OutgoingRPCFactory) WebsocketOption
func WithDefaultHandler ¶
func WithDefaultHandler(h RPCContainerHandler) WebsocketOption
func WithHandler ¶
func WithHandler(predicate string, h RPCContainerHandler) WebsocketOption
func WithOnConnectHandler ¶
func WithOnConnectHandler(f OnConnectHandler) WebsocketOption
func WithPingTime ¶
func WithPingTime(t time.Duration) WebsocketOption
func WithPredicateKey ¶
func WithPredicateKey(key string) WebsocketOption
func WithPreflightRPC ¶ added in v0.9.5
func WithPreflightRPC(h ...RPCPreflightHandler) WebsocketOption
WithPreflightRPC register one or many handlers to run in sequence before actually making requests.
func WithUpgradeHeader ¶
func WithUpgradeHeader(key string, values ...string) WebsocketOption