Documentation
¶
Index ¶
- type ChatMessage
- type ChatResponse
- func NewChatResponse(msgType, content string) *ChatResponse
- func NewErrorResponse(content string) *ChatResponse
- func NewMessageResponse(content string, user *User) *ChatResponse
- func NewPongResponse() *ChatResponse
- func NewStatusResponse(content string) *ChatResponse
- func NewTraceResponse(content string, user *User) *ChatResponse
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatMessage ¶
type ChatMessage struct {
Type string `json:"type"` // "message", "ping"
Content string `json:"content"` // message content
Timestamp int64 `json:"timestamp"` // unix timestamp
}
ChatMessage represents a message sent from client to server
func (*ChatMessage) FromBytes ¶
func (m *ChatMessage) FromBytes(data []byte) error
FromBytes parses JSON bytes to ChatMessage
func (*ChatMessage) IsValidMessageType ¶
func (m *ChatMessage) IsValidMessageType() bool
IsValidMessageType checks if message type is valid
type ChatResponse ¶
type ChatResponse struct {
Type string `json:"type"` // "message", "history", "status", "error", "pong", "trace"
Content string `json:"content"` // message content
User *User `json:"user,omitempty"` // sender information
Timestamp int64 `json:"timestamp"` // unix timestamp
MessageID string `json:"message_id,omitempty"` // unique message identifier
}
ChatResponse represents a message sent from server to client
func NewChatResponse ¶
func NewChatResponse(msgType, content string) *ChatResponse
NewChatResponse creates a new ChatResponse with current timestamp
func NewErrorResponse ¶
func NewErrorResponse(content string) *ChatResponse
NewErrorResponse creates an error response
func NewMessageResponse ¶
func NewMessageResponse(content string, user *User) *ChatResponse
NewMessageResponse creates a chat message response
func NewStatusResponse ¶
func NewStatusResponse(content string) *ChatResponse
NewStatusResponse creates a status response
func NewTraceResponse ¶
func NewTraceResponse(content string, user *User) *ChatResponse
NewTraceResponse creates a trace message response
func (*ChatResponse) IsValidResponseType ¶
func (r *ChatResponse) IsValidResponseType() bool
IsValidResponseType checks if response type is valid
func (*ChatResponse) ToBytes ¶
func (r *ChatResponse) ToBytes() ([]byte, error)
ToBytes converts ChatResponse to JSON bytes
Click to show internal directories.
Click to hide internal directories.