ws

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package ws is partially based on the http package from go-kit. The code in this file is based on code from http package of go-kit project (https://github.com/go-kit/kit/blob/master/transport/http/intercepting_writer.go). All rights of the code belong to the original author.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client[OUT, IN any] struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient[OUT, IN any](
	url url.URL,
	enc EncodeFunc[OUT],
	dec DecodeFunc[IN],
	closure Closure,
	opts ...ClientOption,
) *Client[OUT, IN]

func (*Client[OUT, IN]) Endpoint

func (c *Client[OUT, IN]) Endpoint() endpoint.BiStream[OUT, IN]

type ClientOption

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

func WithClientAfter

func WithClientAfter(after ClientTunerFunc) ClientOption

func WithClientBefore

func WithClientBefore(before DiallerFunc) ClientOption

func WithClientErrorHandler

func WithClientErrorHandler(handler transport.ErrorHandler) ClientOption

func WithClientFinalizer

func WithClientFinalizer(finalizer kithttp.ClientFinalizerFunc) ClientOption

func WithClientPing

func WithClientPing(period, await time.Duration, pinging Pinging) ClientOption

func WithClientReadTimeout

func WithClientReadTimeout(timeout time.Duration) ClientOption

func WithClientWriteMod added in v0.0.4

func WithClientWriteMod(mod WriteMod) ClientOption

func WithClientWriteTimeout

func WithClientWriteTimeout(timeout time.Duration) ClientOption

type ClientTunerFunc added in v0.0.4

type ClientTunerFunc func(context.Context, *http.Response, Tuner) context.Context

type CloseCode

type CloseCode int
const (
	NormalClosureCloseCode           CloseCode = websocket.CloseNormalClosure
	GoingAwayCloseCode               CloseCode = websocket.CloseGoingAway
	ProtocolErrorCloseCode           CloseCode = websocket.CloseProtocolError
	UnsupportedDataCloseCode         CloseCode = websocket.CloseUnsupportedData
	NoStatusReceivedCloseCode        CloseCode = websocket.CloseNoStatusReceived
	AbnormalClosureCloseCode         CloseCode = websocket.CloseAbnormalClosure
	InvalidFramePayloadDataCloseCode CloseCode = websocket.CloseInvalidFramePayloadData
	PolicyViolationCloseCode         CloseCode = websocket.ClosePolicyViolation
	MessageTooBigCloseCode           CloseCode = websocket.CloseMessageTooBig
	MandatoryExtensionCloseCode      CloseCode = websocket.CloseMandatoryExtension
	InternalServerErrCloseCode       CloseCode = websocket.CloseInternalServerErr
	ServiceRestartCloseCode          CloseCode = websocket.CloseServiceRestart
	TryAgainLaterCloseCode           CloseCode = websocket.CloseTryAgainLater
	TLSHandshakeCloseCode            CloseCode = websocket.CloseTLSHandshake
)

func (CloseCode) String

func (c CloseCode) String() string

type Closure

type Closure func(context.Context, error) (code CloseCode, msg string, deadline time.Time)

type DecodeFunc

type DecodeFunc[T any] func(context.Context, MessageType, []byte) (T, error)

type Dialler added in v0.0.4

type Dialler interface {
	SetNetDial(dial func(network, addr string) (net.Conn, error))
	SetNetDialContext(func(ctx context.Context, network, addr string) (net.Conn, error))
	SetNetDialTLSContext(func(ctx context.Context, network, addr string) (net.Conn, error))
	SetProxy(func(*http.Request) (*url.URL, error))
	SetTLSClientConfig(*tls.Config)
	SetHandshakeTimeout(time.Duration)
	SetReadBufferSize(int)
	SetWriteBufferSize(int)
	SetWriteBufferPool(websocket.BufferPool)
	SetSubprotocols([]string)
	SetEnableCompression(bool)
	SetJar(http.CookieJar)
}

type DiallerFunc added in v0.0.4

type DiallerFunc func(context.Context, Dialler, http.Header) context.Context

type EncodeFunc

type EncodeFunc[T any] func(context.Context, T) ([]byte, MessageType, error)

type MessageType

type MessageType int
const (
	TextMessageType   MessageType = websocket.TextMessage
	BinaryMessageType MessageType = websocket.BinaryMessage
)

func (MessageType) String

func (mt MessageType) String() string

type Pinging

type Pinging func(context.Context) (msg []byte, deadline time.Time)

type Server

type Server[IN, OUT any] struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer[IN, OUT any](
	e endpoint.BiStream[IN, OUT],
	dec DecodeFunc[IN],
	enc EncodeFunc[OUT],
	closure Closure,
	opts ...ServerOption,
) *Server[IN, OUT]

func (*Server[IN, OUT]) ServeHTTP

func (s *Server[IN, OUT]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerOption

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

func WithServerBefore

func WithServerBefore(before UpgradeFunc) ServerOption

func WithServerErrorHandler

func WithServerErrorHandler(handler transport.ErrorHandler) ServerOption

func WithServerFinalizer

func WithServerFinalizer(finalizer kithttp.ServerFinalizerFunc) ServerOption

func WithServerPing

func WithServerPing(period, await time.Duration, pinging Pinging) ServerOption

func WithServerReadTimeout

func WithServerReadTimeout(timeout time.Duration) ServerOption

func WithServerWriteMod added in v0.0.4

func WithServerWriteMod(mod WriteMod) ServerOption

func WithServerWriteTimeout

func WithServerWriteTimeout(timeout time.Duration) ServerOption

type ServerTunerFunc added in v0.0.4

type ServerTunerFunc func(context.Context, Tuner) context.Context

type Tuner added in v0.0.4

type Tuner interface {
	EnableWriteCompression(enable bool)
	SetCompressionLevel(level int) error
	SetReadLimit(limit int64)
}

type UpgradeFunc added in v0.0.4

type Upgrader added in v0.0.4

type Upgrader interface {
	SetHandshakeTimeout(timeout time.Duration)
	SetReadBufferSize(size int)
	SetWriteBufferSize(size int)
	SetWriteBufferPool(pool websocket.BufferPool)
	SetSubprotocols(protocols []string)
	SetErrorWriter(writer func(w http.ResponseWriter, r *http.Request, status int, reason error))
	SetCheckOrigin(check func(r *http.Request) bool)
	SetEnableCompression(enabled bool)
}

type WriteMod added in v0.0.4

type WriteMod uint8
const (
	WriteModPlain WriteMod = iota + 1
	WriteModPrepared
)

Jump to

Keyboard shortcuts

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