irt

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWriteWaitTime      = 10 * time.Second
	DefaultPongWaitTime       = 60 * time.Second
	DefaultPingPeriod         = (DefaultPongWaitTime * 9) / 10
	DefaultMaxPackageSize     = 1024 * 1024 * 16 // 16 MB
	DefaultReadBufferSize     = 1024 * 8         // 8 KB
	DefaultWriteBufferSize    = 1024 * 8         // 8 KB
	DefaultProcessingThreads  = 2
	DefaultRegistrationBuffer = 2
	DefaultConnectionBuffer   = 5

	MessageRandomSymbols = "abcdefghijklmnopqrstuvwxyz0123456789"
	MessageRandomLength  = 32

	MessageKindFailure        = "?:failure"
	MessageKindRPCRequest     = "rpc:request"
	MessageKindRPCResponse    = "rpc:response"
	MessageKindRPCFailure     = "rpc:failure"
	MessageKindBuzzerRequest  = "buzzer:request"
	MessageKindBuzzerResponse = "buzzer:request"
	MessageKindBuzzerFailure  = "buzzer:request"
	MessageKindStreamS2C      = "stream:s2c"
	MessageKindStreamC2S      = "stream:c2s"
)
View Source
const (
	DefaultTimeout = time.Second * 60
)

Variables

View Source
var DATETIME_FORMATS = []string{
	"2006-01-02T15:04:05Z07:00",
	"2006-01-02T15:04:05.0Z07:00",
	"2006-01-02T15:04:05.00Z07:00",
	"2006-01-02T15:04:05.000Z07:00",
	"2006-01-02T15:04:05.0000Z07:00",
	"2006-01-02T15:04:05.00000Z07:00",
	"2006-01-02T15:04:05.000000Z07:00",
	"2006-01-02T15:04:05.0000000Z07:00",
	"2006-01-02T15:04:05.00000000Z07:00",
	"2006-01-02T15:04:05.000000000Z07:00",
	"2006-01-02T15:04:05Z",
	"2006-01-02T15:04:05.0Z",
	"2006-01-02T15:04:05.00Z",
	"2006-01-02T15:04:05.000Z",
	"2006-01-02T15:04:05.0000Z",
	"2006-01-02T15:04:05.00000Z",
	"2006-01-02T15:04:05.000000Z",
	"2006-01-02T15:04:05.0000000Z",
	"2006-01-02T15:04:05.00000000Z",
	"2006-01-02T15:04:05.000000000Z",
	"2006-01-02T15:04:05",
	"2006-01-02T15:04:05.0",
	"2006-01-02T15:04:05.00",
	"2006-01-02T15:04:05.000",
	"2006-01-02T15:04:05.0000",
	"2006-01-02T15:04:05.00000",
	"2006-01-02T15:04:05.000000",
	"2006-01-02T15:04:05.0000000",
	"2006-01-02T15:04:05.00000000",
	"2006-01-02T15:04:05.000000000",
}

TODO Replace with better logic than brute-forcing this thing

Functions

func RandomMessageID

func RandomMessageID(prefix string) string

func ReadDate

func ReadDate(value string) (time.Time, error)

func ReadDateTime

func ReadDateTime(value string, utc bool) (time.Time, error)

func ReadLocalDateTime

func ReadLocalDateTime(value string) (time.Time, error)

func ReadTime

func ReadTime(value string) (time.Time, error)

func ReadUTCDateTime

func ReadUTCDateTime(value string) (time.Time, error)

func ReadZoneDateTime

func ReadZoneDateTime(value string) (time.Time, error)

func WriteDate

func WriteDate(value time.Time) string

func WriteLocalDateTime

func WriteLocalDateTime(value time.Time) string

func WriteTime

func WriteTime(value time.Time) string

func WriteUTCDateTime

func WriteUTCDateTime(value time.Time) string

func WriteZoneDateTime

func WriteZoneDateTime(value time.Time) string

Types

type AuthApiKey

type AuthApiKey struct {
	ApiKey string
}

func NewAuthApiKey

func NewAuthApiKey(apiKey string) *AuthApiKey

type AuthBasic

type AuthBasic struct {
	User string
	Pass string
}

func NewAuthBasic

func NewAuthBasic(user string, pass string) *AuthBasic

func (*AuthBasic) GetPass

func (a *AuthBasic) GetPass() (string, error)

type AuthCustom

type AuthCustom struct {
	Value string
}

func NewAuthCustom

func NewAuthCustom(value string) *AuthCustom

type AuthToken

type AuthToken struct {
	Token string
}

func NewAuthToken

func NewAuthToken(token string) *AuthToken

type Authorization

type Authorization struct {
	ApiKey *AuthApiKey
	Token  *AuthToken
	Basic  *AuthBasic
	Custom *AuthCustom
}

func (*Authorization) Reset

func (c *Authorization) Reset()

func (*Authorization) ToValue

func (c *Authorization) ToValue() string

func (*Authorization) UpdateFromHeaders

func (c *Authorization) UpdateFromHeaders(h http.Header) error

func (*Authorization) UpdateFromRequest

func (c *Authorization) UpdateFromRequest(r http.Request) error

func (*Authorization) UpdateFromValue

func (c *Authorization) UpdateFromValue(auth string) error

type BinaryMarshaller

type BinaryMarshaller struct {
}

func NewBinaryMarshaller

func NewBinaryMarshaller() *BinaryMarshaller

func (*BinaryMarshaller) Marshal

func (m *BinaryMarshaller) Marshal(data interface{}) ([]byte, error)

func (*BinaryMarshaller) Unmarshal

func (m *BinaryMarshaller) Unmarshal(data []byte, model interface{}) error

type ClientSocketTransport

type ClientSocketTransport interface {
	ClientTransport
}

type ClientTransport

type ClientTransport interface {
	GetAuthorization() *Authorization
	SetAuthorization(auth *Authorization) error
	GetHeaders() TransportHeaders
	SetHeaders(headers TransportHeaders) error
	Send(service string, method string, dataIn interface{}, dataOut interface{}) error
}

Client Specific

func NewHTTPClientTransport

func NewHTTPClientTransport(endpoint string, timeout time.Duration) ClientTransport

func NewHTTPClientTransportEx

func NewHTTPClientTransportEx(endpoint string, timeout time.Duration, skipSSLVerify bool, marshaller Marshaller, logger Logger) ClientTransport

func NewWebSocketClientTransport

func NewWebSocketClientTransport(endpoint string, subprotocols []string) (ClientTransport, error)

func NewWebSocketClientTransportEx

func NewWebSocketClientTransportEx(endpoint string, timeout time.Duration, skipSSLVerify bool, subprotocols []string,
	enableCompression bool, marshaller Marshaller, logger Logger) (ClientTransport, error)

type ConnectionContext

type ConnectionContext struct {
	System *SystemContext
	User   interface{}
}

type ConnectionHandlers

type ConnectionHandlers struct {
	OnConnect    OnConnect
	OnAuth       OnAuth
	OnDisconnect OnDisconnect
}

type Dispatcher

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

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(context interface{}, service string, method string, data []byte) (out []byte, derr error)

func (*Dispatcher) Register

func (d *Dispatcher) Register(dispatcher ServiceDispatcher) error

func (*Dispatcher) Unregister

func (d *Dispatcher) Unregister(serviceName string) bool

type JSONMarshaller

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

func NewJSONMarshaller

func NewJSONMarshaller(pretty bool) *JSONMarshaller

func (*JSONMarshaller) Marshal

func (m *JSONMarshaller) Marshal(data interface{}) ([]byte, error)

func (*JSONMarshaller) Unmarshal

func (m *JSONMarshaller) Unmarshal(data []byte, model interface{}) error

type LogLevel

type LogLevel int
const (
	LogTrace LogLevel = iota
	LogDebug
	LogInfo
	LogWarning
	LogError
)

type Logger

type Logger interface {
	Logf(level LogLevel, format string, params ...interface{})
}

func NewConsoleLogger

func NewConsoleLogger(level LogLevel) Logger

func NewDummyLogger

func NewDummyLogger() Logger

type Marshaller

type Marshaller interface {
	Marshal(data interface{}) ([]byte, error)
	Unmarshal(data []byte, model interface{}) error
}

type OnAuth

type OnAuth func(connection *ConnectionContext) error

type OnConnect

type OnConnect func(connection *ConnectionContext, request *http.Request) error

Server specific

type OnDisconnect

type OnDisconnect func(connection *ConnectionContext)

type ServiceDispatcher

type ServiceDispatcher interface {
	Dispatch(context interface{}, method string, data []byte) ([]byte, error)
	GetSupportedService() string
	GetSupportedMethods() []string
}

type SystemContext

type SystemContext struct {
	RemoteAddr string
	Auth       *Authorization
}

func (*SystemContext) Update

func (c *SystemContext) Update(r *http.Request) error

type TransportHeaders

type TransportHeaders = map[string]string

type WebSocketFailureMessage

type WebSocketFailureMessage struct {
	Kind  string `json:"kind"`
	Cause string `json:"cause"`
	Data  string `json:"data"`
}

type WebSocketMessageBase

type WebSocketMessageBase struct {
	Kind string `json:"kind"`
}

type WebSocketRequestMessage

type WebSocketRequestMessage struct {
	Kind    string            `json:"kind"`
	Service string            `json:"service,omitempty"`
	Method  string            `json:"method,omitempty"`
	ID      string            `json:"id"`
	Data    json.RawMessage   `json:"data,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

type WebSocketResponseMessage

type WebSocketResponseMessage struct {
	Kind string          `json:"kind"`
	Ref  string          `json:"ref"`
	Data json.RawMessage `json:"data,omitempty"`
}

type WebSocketServerTransport

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

func NewWebSocketServerTransport

func NewWebSocketServerTransport(dispatcher *Dispatcher, handlers *ConnectionHandlers) *WebSocketServerTransport

func NewWebSocketServerTransportEx

func NewWebSocketServerTransportEx(dispatcher *Dispatcher, marshaller Marshaller, logger Logger,
	handlers *ConnectionHandlers) *WebSocketServerTransport

func (*WebSocketServerTransport) ServeWS

func (*WebSocketServerTransport) Start

func (t *WebSocketServerTransport) Start()

func (*WebSocketServerTransport) Stop

func (t *WebSocketServerTransport) Stop()

Jump to

Keyboard shortcuts

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