Documentation
¶
Index ¶
- Variables
- func BindingErrors(e error) error
- func Code(action string, code int, msg string) []byte
- func Data(action string, data any) []byte
- func Dispatcher(c *Client, request string)
- func HttpHandler(w http.ResponseWriter, r *http.Request)
- func IsValidStatus(s UserOnlineStatus) bool
- func Msg(action, msg string) []byte
- type Action
- type ActionManager
- type ApiData
- type Appid
- type Client
- func (c *Client) Close()
- func (c *Client) GetKey(key string) *Value
- func (c *Client) Log(symbol string, msg ...string)
- func (c *Client) Reader()
- func (c *Client) SendMsg(msg []byte)
- func (c *Client) SendRawMsg(code int, action, msg string, data any)
- func (c *Client) SetKey(key string, value any)
- func (c *Client) Write()
- type Context
- func (c *Context) Abort()
- func (c *Context) BindingJson(s any) error
- func (c *Context) BindingJsonPath(s any, path string) error
- func (c *Context) BindingValidateJson(s any) error
- func (c *Context) Broadcast(msg *Action)
- func (c *Context) Get(key string) string
- func (c *Context) GetBool(key string) bool
- func (c *Context) GetId(key string) uint
- func (c *Context) GetInt(key string) int
- func (c *Context) GetJson(s any) error
- func (c *Context) GetMinInt(key string, min int) int
- func (c *Context) GetPagination() *Pagination
- func (c *Context) GetRangeInt(key string, min, max int) int
- func (c *Context) GetSizePagination(pageSize int) *Pagination
- func (c *Context) GetSliceVal(key string, options ...string) string
- func (c *Context) Next()
- func (c *Context) Send(data any)
- func (c *Context) SendActionData(action string, data any)
- func (c *Context) SendActionMsg(action, msg string)
- func (c *Context) SendCode(code int, msg string)
- func (c *Context) SendMsg(msg string)
- func (c *Context) SendOk()
- func (c *Context) SendRawTo(uid string, msg *Action)
- func (c *Context) SendTo(uid, action string, data any)
- func (c *Context) SendToApp(appId string, msg *Action)
- func (c *Context) SendToApps(msg *Action)
- type Error
- type H
- type HandlerFunc
- type HandlersChain
- type Hubc
- type IRouter
- type Location
- type Page
- type Pagination
- type PubSub
- type Resource
- type Response
- type Routers
- type Server
- type Stack
- type Topic
- type TopicMsg
- type User
- func (u *User) AddSubTopic(topic *Topic) int
- func (u *User) AppClient(appId string) *Client
- func (u *User) Banned(t time.Duration) *time.Time
- func (u *User) IsBanned() (bool, *time.Time)
- func (u *User) IsOnline() bool
- func (u *User) SendMsg(msg []byte)
- func (u *User) SendMsgToApp(appId string, msg []byte)
- func (u *User) Unban() *time.Time
- func (u *User) UnsubTopic(topicId string) int
- type UserOnlineStatus
- type Value
- func (v *Value) Bool() bool
- func (v *Value) Duration() time.Duration
- func (v *Value) Float32() float32
- func (v *Value) Float64() float64
- func (v *Value) Int() int
- func (v *Value) Int8() int8
- func (v *Value) Int16() int16
- func (v *Value) Int32() int32
- func (v *Value) Int64() int64
- func (v *Value) Map() map[string]any
- func (v *Value) Raw() any
- func (v *Value) Slice() []any
- func (v *Value) SliceInt() []int
- func (v *Value) SliceString() []string
- func (v *Value) String() string
- func (v *Value) StringMap() map[string]string
- func (v *Value) Time() time.Time
- func (v *Value) Uint() uint
- func (v *Value) Uint8() uint8
- func (v *Value) Uint16() uint16
- func (v *Value) Uint32() uint32
- func (v *Value) Uint64() uint64
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrServerError = NewError(sys, 1100, "Server under maintenance") ErrUncertified = NewError(sys, 1120, "Please log in first") ErrCertificationExpired = NewError(sys, 1121, "Login has expired") ErrJwtBLOCKED = NewError(sys, 1123, "Login has expired") ErrParamsInvalid = NewError(sys, 1131, "Invalid parameters") ErrAuthentic = NewError(sys, 1141, "Please login first") )
Functions ¶
func Dispatcher ¶
func HttpHandler ¶
func HttpHandler(w http.ResponseWriter, r *http.Request)
func IsValidStatus ¶
func IsValidStatus(s UserOnlineStatus) bool
Types ¶
type Action ¶
type Action struct {
Action string `json:"action"`
Code int `json:"code"`
Msg string `json:"msg,omitempty"`
Data any `json:"data,omitempty"`
}
Action Websocket通讯协议
type ActionManager ¶
type ActionManager struct {
// contains filtered or unexported fields
}
func InitManager ¶
func InitManager() *ActionManager
func (*ActionManager) Add ¶
func (m *ActionManager) Add(name string, router HandlersChain)
func (*ActionManager) Handlers ¶
func (m *ActionManager) Handlers(name string) HandlersChain
func (*ActionManager) Has ¶
func (m *ActionManager) Has(name string) bool
type Client ¶
type Client struct {
Hub *Hubc `json:"-"`
Conn net.Conn `json:"-"`
Send chan []byte `json:"-"`
Endpoint string `json:"-"` //入口地址
OnceId string `json:"-"` //临时ID,扫码登录等场景作为客户端唯一标识
Disconnecting bool `json:"-"` //已被设置为断开状态(消息发送完之后断开连接)
SyncMsg bool `json:"-"` //是否接收消息
LastMsgId int `json:"-"` //最后一条消息ID
RequiredValid bool `json:"-"` //人机验证标识
Validated bool `json:"-"` //是否已验证
ValidExpiry time.Time `json:"-"` //验证有效期
ValidCacheData any `json:"-"` //验证相关缓存数据
AuthCode string `json:"-"` //用于校验JWT中的code,如果相等识别为同一个用户的网络地址变更
ErrorCount int `json:"-"` //错误次数
Closed bool `json:"-"` //是否已经关闭
User *User `json:"user,omitempty"` //关联用户
Scope string `json:"scope"` //登录jwt scope, 用于判断用户从哪里登录的
AppId string `json:"appId"` //登录应用Id
StoreId uint `json:"storeId"` //店铺ID
MerchantId uint `json:"merchantId"` //商户ID
TenantId uint `json:"tenantId"` //租户ID
Platform string `json:"platform"` //登录平台
GroupId string `json:"groupId"` //用户分组Id
IsLogin bool `json:"isLogin"` //是否已登录
LoginAction string `json:"loginAction"` //登录动作
ForceDialogId string `json:"forceDialogId"` //打开聊天界面的会话ID
IpAddress string `json:"ipAddress"` //IP地址
IpLocation string `json:"ipLocation"` //通过IP转换获得的地理位置
IpConnAddr string `json:"IpConnAddr"` //conn连接IP地址
ConnectionTime time.Time `json:"connectionTime"`
LastRequestTime time.Time `json:"lastRequestTime"`
LastHeartbeatTime time.Time `json:"lastHeartbeatTime"`
Keys map[string]any
// contains filtered or unexported fields
}
func (*Client) SendRawMsg ¶
SendRawMsg 构造消息再发送
type Context ¶
type Context struct {
Client *Client
Action string
Params string
Response *Action
Server *Server
// contains filtered or unexported fields
}
func (*Context) BindingJson ¶
func (*Context) BindingValidateJson ¶
func (*Context) GetPagination ¶
func (c *Context) GetPagination() *Pagination
func (*Context) GetSizePagination ¶
func (c *Context) GetSizePagination(pageSize int) *Pagination
func (*Context) SendActionData ¶
SendActionData 发送数据给当前用户
func (*Context) SendActionMsg ¶
SendActionMsg 发送消息给当前用户
type Error ¶
type Error ApiData
func (*Error) WithError ¶
WithError 兼容Binding错误码及多语言翻译 使用前需要调用 validate.GinValidator() 初始化 字段中文名称使用 `label:"名称"` 指定
func (*Error) WithHttpStatus ¶
WithHttpStatus 处理HTTP状态码
type HandlerFunc ¶
type HandlerFunc func(a *Context)
type HandlersChain ¶
type HandlersChain []HandlerFunc
type Hubc ¶
type Hubc struct {
//访客列表
Guests []*Client
//已登录用户 map[string]*User
Users *sync.Map
//用户数统计
LoginCount int
GuestCount int
//发布订阅
PubSub *PubSub
//登录和断开通道
Connection chan *Client
Disconnect chan *Client
}
var Hub *Hubc
type IRouter ¶
type IRouter interface {
Use(middleware ...HandlerFunc) IRouter
Group(name string) IRouter
Add(name string, fn ...HandlerFunc)
}
type Location ¶
type Location struct {
Latitude float64 `json:"latitude" validate:"required"`
Longitude float64 `json:"longitude" validate:"required"`
AdInfo []string `json:"adInfo" validate:"required"`
RegionId string `json:"regionId" validate:"required"`
CityCode string `json:"cityCode" validate:"required"`
Address string `json:"address" validate:"required"`
SelectCityCode string `json:"selectCityCode"` //选择的城市编码
SelectCityName string `json:"selectCityName"` //选择的城市名称
LatestUpdateAt time.Time
}
type Pagination ¶
type Pagination struct {
*Page `json:"page"`
Rows any `json:"rows,omitempty"`
ExData H `json:"exData,omitempty"`
Limit int `json:"-"` //PageSize alias
Offset int `json:"-"` //避免每次计算offset
}
func InitPagination ¶
func InitPagination(p *Page, maxSize int) *Pagination
func (*Pagination) AddExData ¶
func (p *Pagination) AddExData(key string, val any)
type PubSub ¶
type Routers ¶
type Routers struct {
// contains filtered or unexported fields
}
func (Routers) Add ¶
func (r Routers) Add(name string, fn ...HandlerFunc)
func (Routers) Use ¶
func (r Routers) Use(middleware ...HandlerFunc) IRouter
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Handler ¶
func (s *Server) Handler(fn http.HandlerFunc)
func (*Server) SetDataPath ¶
type Topic ¶
type Topic struct {
Id string //订阅主题ID
PubSub *PubSub //关联PubSub
SubUsers sync.Map //SubUsers map[string]*time.Time //订阅用户uniqueId和订阅时间
SubHandlers sync.Map //SubHandlers map[string]func(msg *TopicMsg) //内部组件间通知
}
func (*Topic) AddSubHandle ¶
func (*Topic) AddSubUser ¶
func (*Topic) SendToSubUser ¶
type User ¶
type User struct {
//公共基础信息
Uid uint `json:"uid"` //整型唯一ID
Suid string `json:"suid"` //字符唯一ID
GroupId string `json:"groupId"` //分组ID
SuperAdmin bool `json:"superAdmin"` //是否超管
RoleId []uint `json:"roleId,omitempty"` //用户角色
Nickname string `json:"nickname"` //昵称
Avatar *Resource `json:"avatar"` //用户头像
OnlineStatus UserOnlineStatus `json:"onlineStatus"` //在线状态
Location *Location `json:"location,omitempty"` //地理位置
CurrentWindowId string //当前的窗口ID
//禁言时间
Ban *time.Time `json:"ban,omitempty"`
//最后心跳时间
LastHeartbeatTime time.Time
//用户相关数据
Hub *Hubc `json:"-"`
AppClients []*Client `json:"-"` //appId对应客户端
SubTopics map[string]*Topic `json:"-"` //topicId订阅的主题名称及信息
sync.RWMutex
}
func (*User) AddSubTopic ¶
func (*User) SendMsgToApp ¶
SendMsgToApp 发送消息到指定客户端
func (*User) UnsubTopic ¶
type UserOnlineStatus ¶
type UserOnlineStatus byte
const ( UserStatusOnline UserOnlineStatus = iota UserStatusBusy UserStatusLeaving )
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
func (*Value) SliceString ¶
Source Files
¶
- client.go
- client_keyval.go
- client_stack.go
- context.go
- context_binding.go
- context_i18n.go
- context_lang.go
- context_params.go
- context_send.go
- context_value.go
- data_api.go
- data_appid.go
- data_error.go
- data_h.go
- data_paginate.go
- dispatcher.go
- hubc.go
- manager.go
- pubsub.go
- pubsub_topic.go
- pubsub_topic_msg.go
- router.go
- server.go
- server_handler_http.go
- user.go
- user_location.go
- user_resource.go
- user_status.go
- w.go
- w_response.go
- w_util.go
- w_util_binding.go
- w_util_chain.go
Click to show internal directories.
Click to hide internal directories.