Documentation ¶
Index ¶
- Constants
- func CheckAuthority(tk string, verify token.Verify, role ...string) (uid string, err error)
- func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)
- type Channel
- type ChannelHandler
- type ChannelSet
- type CheckMessageReq
- type CheckedMessage
- type Client
- type ClientSet
- type ErrorMessage
- type Handler
- type HistoryMessageReq
- type Hub
- type LoginReq
- type LoginResp
- type Message
- type PackageReq
- type PackageResp
- type TotalUncheckedMessage
- type WrapPackageReq
Constants ¶
View Source
const ( ErrExpired = "Login expired, please login again." ErrForbidden = "Forbidden." ErrInternalServer = "Internal server error." ErrUserNotFound = "User doesn't exist." ErrMessageEmpty = "Empty message." )
Variables ¶
This section is empty.
Functions ¶
func CheckAuthority ¶
Types ¶
type Channel ¶
type Channel string
const ( MessageError Channel = "message_error" // unsubscribe message Login Channel = "login" Logout Channel = "logout" ChatSend Channel = "chat_send" ChatCheck Channel = "chat_check" // subscribe message Echo Channel = "echo" ChatReceive Channel = "chat_receive" ChatPartners Channel = "chat_partners" ChatHistory Channel = "chat_history" ChatPartnersStatus Channel = "chat_partners_status" ChatCheckedStatus Channel = "chat_checked_status" ChatUncheckedList Channel = "chat_unchecked_list" ChatUncheckedTotal Channel = "chat_unchecked_total" MaxWsConnsOneUser = 20 // max websocket connections one user )
type ChannelHandler ¶
type ChannelSet ¶
type ChannelSet struct {
// contains filtered or unexported fields
}
func NewChannelSet ¶
func NewChannelSet(channels ...Channel) *ChannelSet
func (*ChannelSet) Add ¶
func (s *ChannelSet) Add(channels ...Channel)
func (*ChannelSet) Clear ¶
func (s *ChannelSet) Clear()
func (*ChannelSet) Contains ¶
func (s *ChannelSet) Contains(channel Channel) bool
func (*ChannelSet) Map ¶
func (s *ChannelSet) Map(f func(channel Channel))
func (*ChannelSet) Remove ¶
func (s *ChannelSet) Remove(channels ...Channel)
func (*ChannelSet) Size ¶
func (s *ChannelSet) Size() int
type CheckMessageReq ¶
type CheckMessageReq struct {
Partner string `json:"partner"`
}
CheckMessageReq is to check chat message request
type CheckedMessage ¶
type CheckedMessage struct {
Partner string `json:"partner"`
}
CheckedMessage is notify to client update checked status of partner's chat message
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a middleman between the websocket connection and the hub.
type ClientSet ¶
type ClientSet struct {
// contains filtered or unexported fields
}
func NewClientSet ¶
type ErrorMessage ¶
type Handler ¶
type Handler func(pkg *WrapPackageReq)
type HistoryMessageReq ¶
type HistoryMessageReq struct { Partner string `json:"partner" form:"partner" binding:"required"` Before *types.UnixTime `json:"before,omitempty" form:"before"` Limit int `json:"limit" form:"limit" binding:"required,min=1,max=100" example:"20"` }
HistoryMessageReq is history chat message request
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients.
func (*Hub) DeliverSystemMessage ¶
func (*Hub) RegisterHandler ¶
type Message ¶
type Message struct { Sender string `json:"sender,omitempty"` Recipient string `json:"recipient"` Type int8 `json:"type"` // 0:text message Content string `json:"content"` Timestamp *types.UnixTime `json:"timestamp,omitempty"` Checked bool `json:"checked"` }
Message is chat message
type PackageReq ¶
type PackageReq struct { Channel Channel `json:"channel"` Subscribe *bool `json:"subscribe,omitempty"` Body json.RawMessage `json:"body,omitempty"` }
type PackageResp ¶
type PackageResp struct { Channel Channel `json:"channel"` Body interface{} `json:"body,omitempty"` }
type TotalUncheckedMessage ¶
type TotalUncheckedMessage struct {
Total int64 `json:"total"`
}
TotalUncheckedMessage is total unchecked chat messages
type WrapPackageReq ¶
type WrapPackageReq struct { PackageReq Sender *Client Raw []byte }
Click to show internal directories.
Click to hide internal directories.