ws

package
v3.9.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 23 Imported by: 33

Documentation

Index

Constants

View Source
const (
	GenEndpointUri = "/callback/ws/endpoint"
	DeviceID       = "device_id"
	ServiceID      = "service_id"
)
View Source
const (
	HeaderTimestamp            = "timestamp"   // 消息时间戳, 单位ms
	HeaderType                 = "type"        // 消息类型, Event/Card
	HeaderMessageID            = "message_id"  // 消息ID, 拆包后继承
	HeaderSum                  = "sum"         // 拆包数, 未拆包为1
	HeaderSeq                  = "seq"         // 包序号, 未拆包为0
	HeaderTraceID              = "trace_id"    // 链路ID
	HeaderInstanceID           = "instance_id" // 标识下行消息来源及上行消息去向的机器实例地址, 由 ip、port、pod_name 等信息加密获得
	HeaderBizRt                = "biz_rt"      // 业务处理时长,单位ms
	HeaderHandshakeStatus      = "Handshake-Status"
	HeaderHandshakeMsg         = "Handshake-Msg"
	HeaderHandshakeAuthErrCode = "Handshake-Autherrcode"
)
View Source
const (
	OK              = 0
	SystemBusy      = 1
	Forbidden       = 403
	AuthFailed      = 514
	ExceedConnLimit = 1000040350
	InternalError   = 1000040343
)

Variables

View Source
var (
	ErrInvalidLengthPbbp2        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowPbbp2          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupPbbp2 = fmt.Errorf("proto: unexpected end of group")
)

Functions

This section is empty.

Types

type BootstrapRequest added in v3.7.1

type BootstrapRequest struct {
	AppID           string `json:"AppID"`
	AppSecret       string `json:"AppSecret"`
	ClientAssertion string `json:"ClientAssertion"`
}

type Client

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

func NewClient

func NewClient(appId, appSecret string, opts ...ClientOption) *Client

func (*Client) Close added in v3.8.1

func (c *Client) Close()

func (*Client) EventHandler added in v3.8.1

func (c *Client) EventHandler() *dispatcher.EventDispatcher

EventHandler returns the configured event dispatcher.

func (*Client) SetOnDisconnected added in v3.8.1

func (c *Client) SetOnDisconnected(f func())

func (*Client) SetOnError added in v3.8.1

func (c *Client) SetOnError(f func(err error))

func (*Client) SetOnReady added in v3.8.1

func (c *Client) SetOnReady(f func())

func (*Client) SetOnReconnected added in v3.8.1

func (c *Client) SetOnReconnected(f func())

func (*Client) SetOnReconnecting added in v3.8.1

func (c *Client) SetOnReconnecting(f func())

func (*Client) Start

func (c *Client) Start(ctx context.Context) (err error)

type ClientConfig

type ClientConfig struct {
	ReconnectCount    int `json:"ReconnectCount,omitempty"`
	ReconnectInterval int `json:"ReconnectInterval,omitempty"`
	ReconnectNonce    int `json:"ReconnectNonce,omitempty"`
	PingInterval      int `json:"PingInterval,omitempty"`
}

ClientConfig 由服务端下发

type ClientError

type ClientError struct {
	Code int
	Msg  string
}

func NewClientError

func NewClientError(code int, msg string) *ClientError

func (*ClientError) Error

func (e *ClientError) Error() string

type ClientOption

type ClientOption func(cli *Client)

func WithAutoReconnect

func WithAutoReconnect(b bool) ClientOption

func WithClientAssertionProvider added in v3.7.1

func WithClientAssertionProvider(provider larkcore.ClientAssertionProvider) ClientOption

func WithDomain

func WithDomain(domain string) ClientOption

func WithEventHandler

func WithEventHandler(handler *dispatcher.EventDispatcher) ClientOption

func WithLogLevel

func WithLogLevel(level larkcore.LogLevel) ClientOption

func WithLogger

func WithLogger(logger larkcore.Logger) ClientOption

func WithOnDisconnected added in v3.8.1

func WithOnDisconnected(f func()) ClientOption

func WithOnError added in v3.8.1

func WithOnError(f func(err error)) ClientOption

func WithOnReady added in v3.8.1

func WithOnReady(f func()) ClientOption

func WithOnReconnected added in v3.8.1

func WithOnReconnected(f func()) ClientOption

func WithOnReconnecting added in v3.8.1

func WithOnReconnecting(f func()) ClientOption

type Endpoint

type Endpoint struct {
	Url          string        `json:"URL,omitempty"`
	ClientConfig *ClientConfig `json:"ClientConfig,omitempty"`
}

type EndpointResp

type EndpointResp struct {
	Code int       `json:"code"`
	Msg  string    `json:"msg"`
	Data *Endpoint `json:"data"`
}

type Frame

type Frame struct {
	SeqID           uint64   `protobuf:"varint,1,req,name=SeqID" json:"SeqID"`
	LogID           uint64   `protobuf:"varint,2,req,name=LogID" json:"LogID"`
	Service         int32    `protobuf:"varint,3,req,name=service" json:"service"`
	Method          int32    `protobuf:"varint,4,req,name=method" json:"method"`
	Headers         []Header `protobuf:"bytes,5,rep,name=headers" json:"headers"`
	PayloadEncoding string   `protobuf:"bytes,6,opt,name=payload_encoding" json:"payload_encoding"`
	PayloadType     string   `protobuf:"bytes,7,opt,name=payload_type" json:"payload_type"`
	Payload         []byte   `protobuf:"bytes,8,opt,name=payload" json:"payload"`
	LogIDNew        string   `protobuf:"bytes,9,opt,name=LogIDNew" json:"LogIDNew"`
}

message frame

func NewPingFrame

func NewPingFrame(serviceID int32) *Frame

func (*Frame) Descriptor

func (*Frame) Descriptor() ([]byte, []int)

func (*Frame) GetHeaders

func (m *Frame) GetHeaders() []Header

func (*Frame) GetLogID

func (m *Frame) GetLogID() uint64

func (*Frame) GetLogIDNew

func (m *Frame) GetLogIDNew() string

func (*Frame) GetMethod

func (m *Frame) GetMethod() int32

func (*Frame) GetPayload

func (m *Frame) GetPayload() []byte

func (*Frame) GetPayloadEncoding

func (m *Frame) GetPayloadEncoding() string

func (*Frame) GetPayloadType

func (m *Frame) GetPayloadType() string

func (*Frame) GetSeqID

func (m *Frame) GetSeqID() uint64

func (*Frame) GetService

func (m *Frame) GetService() int32

func (*Frame) Marshal

func (m *Frame) Marshal() (dAtA []byte, err error)

func (*Frame) MarshalTo

func (m *Frame) MarshalTo(dAtA []byte) (int, error)

func (*Frame) MarshalToSizedBuffer

func (m *Frame) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Frame) ProtoMessage

func (*Frame) ProtoMessage()

func (*Frame) Reset

func (m *Frame) Reset()

func (*Frame) Size

func (m *Frame) Size() (n int)

func (*Frame) String

func (m *Frame) String() string

func (*Frame) Unmarshal

func (m *Frame) Unmarshal(dAtA []byte) error

func (*Frame) XXX_DiscardUnknown

func (m *Frame) XXX_DiscardUnknown()

func (*Frame) XXX_Marshal

func (m *Frame) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Frame) XXX_Merge

func (m *Frame) XXX_Merge(src proto.Message)

func (*Frame) XXX_Size

func (m *Frame) XXX_Size() int

func (*Frame) XXX_Unmarshal

func (m *Frame) XXX_Unmarshal(b []byte) error

type FrameType

type FrameType int
const (
	FrameTypeControl FrameType = 0
	FrameTypeData    FrameType = 1
)
type Header struct {
	Key   string `protobuf:"bytes,1,req,name=key" json:"key"`
	Value string `protobuf:"bytes,2,req,name=value" json:"value"`
}

func (*Header) Descriptor

func (*Header) Descriptor() ([]byte, []int)

func (*Header) GetKey

func (m *Header) GetKey() string

func (*Header) GetValue

func (m *Header) GetValue() string

func (*Header) Marshal

func (m *Header) Marshal() (dAtA []byte, err error)

func (*Header) MarshalTo

func (m *Header) MarshalTo(dAtA []byte) (int, error)

func (*Header) MarshalToSizedBuffer

func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) Reset

func (m *Header) Reset()

func (*Header) Size

func (m *Header) Size() (n int)

func (*Header) String

func (m *Header) String() string

func (*Header) Unmarshal

func (m *Header) Unmarshal(dAtA []byte) error

func (*Header) XXX_DiscardUnknown

func (m *Header) XXX_DiscardUnknown()

func (*Header) XXX_Marshal

func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Header) XXX_Merge

func (m *Header) XXX_Merge(src proto.Message)

func (*Header) XXX_Size

func (m *Header) XXX_Size() int

func (*Header) XXX_Unmarshal

func (m *Header) XXX_Unmarshal(b []byte) error

type Headers

type Headers []Header

Headers Frame.Headers

func (*Headers) Add

func (h *Headers) Add(key, value string)

func (Headers) GetInt

func (h Headers) GetInt(key string) int

func (Headers) GetString

func (h Headers) GetString(key string) string

type MessageType

type MessageType string
const (
	MessageTypeEvent MessageType = "event"
	MessageTypeCard  MessageType = "card"
	MessageTypePing  MessageType = "ping"
	MessageTypePong  MessageType = "pong"
)

type Response

type Response struct {
	StatusCode int               `json:"code"`
	Headers    map[string]string `json:"headers"`
	Data       []byte            `json:"data"`
}

Response 上行响应消息结构, 置于 Frame.Payload

func NewResponseByCode

func NewResponseByCode(code int) *Response

type ServerError

type ServerError struct {
	Code int
	Msg  string
}

func NewServerError

func NewServerError(code int, msg string) *ServerError

func (*ServerError) Error

func (e *ServerError) Error() string

Jump to

Keyboard shortcuts

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