im

package module
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: LGPL-3.0 Imports: 34 Imported by: 0

README

IM

一个基于websocket的聊天简单工具

可以分布式运行,一台机器也可以启几个,但需要改运行端口 服务器之间通过GRPC 通讯。

然后使用网页打开,比如:

http://127.0.0.1:7070/index?msg=1

http://127.0.0.1:7071/index?msg=1

http://127.0.0.1:7072/index?msg=1

相关GRPC测试,可以通过POSTMAN, img.png

Documentation

Index

Constants

View Source
const (
	CmdRegister   = 1
	CmdUnRegister = 2
	CmdClose      = 3
	CmdKick       = 4
)
View Source
const (
	ETException = EventType(1)

	ETClientPing    = EventType(2)
	ETClientPingRsp = EventType(3)

	// ETClientBegin 客户端开始
	ETClientBegin        = EventType(10)
	ETClientHeartBeat    = EventType(10)
	ETClientHeartBeatRsp = EventType(11)

	// ETClientLogin 登录
	ETClientLogin    = EventType(100)
	ETClientLoginRsp = EventType(101)

	ETClientLogout    = EventType(102)
	ETClientLogoutRsp = EventType(103)

	// ETClientUserStatusChanged 用户状态发生变化
	ETClientUserStatusChanged    = EventType(104)
	ETClientUserStatusChangedRes = EventType(105)

	ETClientUserList    = EventType(106)
	ETClientUserListRsp = EventType(107)

	// ETClientKicked 多端使用,被踢
	ETClientKicked = EventType(108)

	// ETMessage 消息事件
	ETMessage    = EventType(200)
	ETMessageRsp = EventType(201)

	ETNotify    = EventType(202)
	ETNotifyRsp = EventType(203)

	// ETChat 聊天事件
	ETChat    = EventType(204)
	ETChatRsp = EventType(205)

	// ETMq 简单的mq
	ETMq    = EventType(206)
	ETMqRsp = EventType(207)

	// ETClientEnd 客户端结束
	ETClientEnd = EventType(4999)

	// ETServerBegin 服务之间
	ETServerBegin = EventType(5000)

	ETServerEnd = EventType(10000)

	// ETExServerBegin 外部服务
	ETExServerBegin = EventType(20000)

	ETExServerEnd = EventType(30000)
)
View Source
const (
	SubscribeMQ = iota
	UnSubscribeMQ
	SendMQ
)
View Source
const (
	StatusOffline   = 1
	StatusOnline    = 2
	StatusHeartbeat = 3
)
View Source
const EnableUserType = 1000
View Source
const HandshakeTimeoutType = 10000
View Source
const (
	IgnoreStatusBroadcast = 1
)
View Source
const OfflineType = 1001
View Source
const OnlineType = 1002
View Source
const UserHeartbeatTimeout = 180

UserHeartbeatTimeout 3分钟

Variables

View Source
var (
	EmptyByte = []byte("")
)
View Source
var GrcClientNil = result.Error(-102, "not exist remote server")
View Source
var IAmNotMemberErr = errors.New("i am not member")
View Source
var Ignored = result.Error(-103, "ignore the error")
View Source
var NotExistRemoteServer = result.Error(-100, "not exist remote server")
View Source
var OfflineOpt = option.WithOpt(true, "im_offline", OfflineType)
View Source
var OnlineOpt = option.WithOpt(true, "im_offline", OnlineType)
View Source
var StatusDesc = map[int32]string{
	StatusOffline: "离开",
	StatusOnline:  "在线",
}
View Source
var UserObjNil = result.Error(-101, "not exist remote server")

Functions

func ContentQuote

func ContentQuote(d interface{}) string

func IsClientEvent

func IsClientEvent(ev int32) bool

func IsEventResp added in v0.1.27

func IsEventResp(ev int32) bool

func IsExServerEvent

func IsExServerEvent(ev int32) bool

func IsMQEvent added in v0.2.11

func IsMQEvent(ev int32) bool

func IsServerEvent

func IsServerEvent(ev int32) bool

func IsUserStatusChanged

func IsUserStatusChanged(ev int32) bool

func NewContext added in v0.1.18

func NewContext(ctx context.Context, traceId string) context.Context

func NewWithTraceId added in v0.1.9

func NewWithTraceId(traceId string) context.Context

func Register

func Register(key int32, value DisposeFunc)

func SdkVersion added in v0.2.9

func SdkVersion() string

func SessionToPBSession

func SessionToPBSession(session *Session, token string) *pb.Session

func SessionToPBUser

func SessionToPBUser(session *Session) *pb.User

func StringEvent added in v0.1.9

func StringEvent(e int32) string

func ToPBEvent

func ToPBEvent(ev *Event) *pb.Event

func WithHandshakeTimeout added in v0.1.22

func WithHandshakeTimeout(t time.Duration) option.Option

Types

type App

type App struct {
	AppId string `form:"appId" binding:"required" json:"appId" yaml:"appId"`
	Plat  int32  `form:"plat" binding:"-" json:"plat" yaml:"plat"`
}

type Client

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

func BuildClient added in v0.1.22

func BuildClient(clientConn ClientConn, info ConnectInfo, url string, index, firstTime int64, head http.Header, resp func(resp *http.Response), opts ...option.Option) *Client

BuildClient for client

func NewClient

func NewClient(clientConn ClientConn, conn *websocket.Conn, info ConnectInfo, addr string, index, firstTime int64) *Client

func (*Client) Close added in v0.1.22

func (c *Client) Close(ctx context.Context, reason string) error

func (*Client) GetAccount added in v0.3.8

func (c *Client) GetAccount() string

func (*Client) GetAddr added in v0.3.8

func (c *Client) GetAddr() string

func (*Client) GetAppId added in v0.3.8

func (c *Client) GetAppId() string

func (*Client) GetClientId added in v0.3.8

func (c *Client) GetClientId() uint64

func (*Client) GetClientType added in v0.3.8

func (c *Client) GetClientType() int32

func (*Client) GetConnectId added in v0.3.8

func (c *Client) GetConnectId() uint64

func (*Client) GetConnectTime added in v0.3.8

func (c *Client) GetConnectTime() int64

func (*Client) GetHeartTime added in v0.3.8

func (c *Client) GetHeartTime() int64

func (*Client) GetIndex added in v0.3.8

func (c *Client) GetIndex() int64

func (*Client) GetLoginTime added in v0.3.8

func (c *Client) GetLoginTime() int64

func (*Client) GetOrgId added in v0.3.8

func (c *Client) GetOrgId() int32

func (*Client) GetPlatform added in v0.3.8

func (c *Client) GetPlatform() int32

func (*Client) GetRemoteAddr added in v0.3.8

func (c *Client) GetRemoteAddr() string

func (*Client) GetSession added in v0.1.10

func (c *Client) GetSession() Session

func (*Client) GetSource added in v0.2.11

func (c *Client) GetSource() string

func (*Client) GetSyncTime added in v0.3.8

func (c *Client) GetSyncTime() int64

func (*Client) GetTenantId added in v0.3.8

func (c *Client) GetTenantId() int32

func (*Client) GetToken added in v0.1.10

func (c *Client) GetToken() string

func (*Client) GetUserId added in v0.3.8

func (c *Client) GetUserId() uint64

func (*Client) IsClosed

func (c *Client) IsClosed() bool

func (*Client) IsLogin

func (c *Client) IsLogin() bool

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login send login pack

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout send logout pack

func (*Client) Run added in v0.1.22

func (c *Client) Run()

func (*Client) Send added in v0.2.20

func (c *Client) Send(ctx context.Context, eventType EventType, body []byte) error

func (*Client) SendMQ added in v0.2.11

func (c *Client) SendMQ(ctx context.Context, topic string, content string) error

SendMQ send mq pack

func (*Client) SendTo

func (c *Client) SendTo(msg []byte) error

func (*Client) SendToQueue

func (c *Client) SendToQueue(ctx context.Context, msg []byte) error

func (*Client) String

func (c *Client) String() string

func (*Client) Subscribe added in v0.2.11

func (c *Client) Subscribe(ctx context.Context, topic ...string) error

Subscribe send subscribe pack

func (*Client) UnSubscribe added in v0.2.11

func (c *Client) UnSubscribe(ctx context.Context, topic ...string) error

UnSubscribe send unsubscribe pack

func (*Client) WithDisposeFunc added in v0.1.22

func (c *Client) WithDisposeFunc(fn DisposeFunc) *Client

type ClientCmd added in v0.1.22

type ClientCmd struct {
	Cmd     int
	Reason  string
	TraceId string
	Client  *Client
}

type ClientConn added in v0.2.17

type ClientConn interface {
	DoClientCmd(ctx context.Context, cliCmd *ClientCmd)
	DoClientCmdSync(ctx context.Context, cliCmd *ClientCmd)
	StatusChanged(ctx context.Context, us Status)
	OnClose(ctx context.Context)
	OnLogin(ctx context.Context, log LogInfo)
	OnLogout(ctx context.Context, log LogInfo)
	Source() string
}

type Config

type Config struct {
	WorkForceReset bool                                                                                `json:"workForceReset" yaml:"workForceReset"`
	RegisterClient int                                                                                 `json:"registerClient" yaml:"registerClient"`
	ServerAddr     server.Address                                                                      `json:"serverAddr" yaml:"serverAddr"` //服务地址
	TokenCheckFunc func(ctx context.Context, client *Client, token string) error                       `json:"-" yaml:"-"`
	AlarmFunc      func(ctx context.Context, code int32, level int32, title, detail string, err error) `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

type ConnectInfo added in v0.2.17

type ConnectInfo struct {
	Session
	Version  string `form:"version" json:"version" yaml:"version" url:"version"`
	Token    string `form:"token" json:"token" yaml:"token" url:"token"`
	Reason   string `form:"reason" json:"reason" yaml:"reason" url:"reason"`
	RemoteIP string `form:"-" json:"remoteIP" yaml:"-" url:"-"`
}

type Copy added in v0.1.3

type Copy struct {
	Begin   func(count int) interface{}
	Process func(be interface{}, index int, data interface{})
}

type DisposeFunc

type DisposeFunc func(client *Client, req *EventReq) (interface{}, error)

type Event

type Event struct {
	EvTypeBase  int32  `json:"-"`           // 事件基数
	EventType   int32  `json:"eventType"`   // 事件类型, EventType
	ContentType string `json:"contentType"` // Content 格式,json,xml...protobuff, 默认json
	Content     string `json:"content"`     // 具体的业务数据
	TraceId     string `json:"-"`
}

func CreateEvent

func CreateEvent(traceId string, evType EventType, content []byte) *Event

func CreateObjEvent added in v0.2.20

func CreateObjEvent(traceId string, evType EventType, content interface{}) *Event

func PBEventTo

func PBEventTo(ev *pb.Event) *Event

type EventReq

type EventReq struct {
	ReqHead
	Session
	Event
	// 事件相应的回应类型
	EvTypeRsp int32  `json:"-"`
	TraceId   string `json:"-"`
}

func Request

func Request(source string, user *Session) *EventReq

func RequestEvent

func RequestEvent(source string, ev *Event, user *Session) *EventReq

func (*EventReq) ToBytes

func (req *EventReq) ToBytes() []byte

func (*EventReq) ToSession

func (req *EventReq) ToSession() *Session

type EventRes

type EventRes struct {
	ResHead
	Event
}

func NewResponse

func NewResponse(source string, head request.HeadV2, result result.Result, ev *Event) *EventRes

func NewResponseWithError

func NewResponseWithError(source string, head request.HeadV2, err error, ev *Event) *EventRes

type EventType

type EventType int32

func (EventType) Int

func (m EventType) Int() int32

type Hub added in v0.2.11

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

func Inst

func Inst(opts ...Option) *Hub

func NewHub added in v0.2.11

func NewHub(workMod int, opts ...Option) *Hub

func (*Hub) AddClients added in v0.2.11

func (hub *Hub) AddClients(client *Client)

func (*Hub) AddUsers added in v0.2.11

func (hub *Hub) AddUsers(ctx context.Context, key string, client *Client, reason string) int

func (*Hub) Alarm added in v0.2.11

func (hub *Hub) Alarm(ctx context.Context, code int32, level int32, title, detail string, err error)

func (*Hub) CheckAllUserOnline added in v0.2.11

func (hub *Hub) CheckAllUserOnline(session *Session) bool

func (*Hub) CheckUserOnline added in v0.2.11

func (hub *Hub) CheckUserOnline(session *Session) bool

CheckUserOnline 查询用户是否在线

func (*Hub) ClientQuery added in v0.3.8

func (hub *Hub) ClientQuery(f func(client *Client) (result bool))

func (*Hub) ClientSearch added in v0.3.8

func (hub *Hub) ClientSearch(q Query) []*Client

func (*Hub) DelClient added in v0.2.11

func (hub *Hub) DelClient(client *Client)

func (*Hub) DelUser added in v0.2.11

func (hub *Hub) DelUser(ctx context.Context, client *Client) bool

func (*Hub) DoClientCmd added in v0.2.11

func (hub *Hub) DoClientCmd(ctx context.Context, reg *ClientCmd)

func (*Hub) DoClientCmdSync added in v0.2.11

func (hub *Hub) DoClientCmdSync(ctx context.Context, cliCmd *ClientCmd)

func (*Hub) GetAllUserList added in v0.2.11

func (hub *Hub) GetAllUserList(session *Session) *UserList

GetAllUserList 查询所有用户

func (*Hub) GetAppList added in v0.3.5

func (hub *Hub) GetAppList() []string

func (*Hub) GetClients added in v0.2.11

func (hub *Hub) GetClients() []*Client

func (*Hub) GetLocalUserList added in v0.2.11

func (hub *Hub) GetLocalUserList(session *Session) *UserList

GetLocalUserList 本机的用户

func (*Hub) GetOnline added in v0.2.21

func (hub *Hub) GetOnline(session *Session, opt ...option.Option) *OnLineList

GetOnline 在线或离线用户

func (*Hub) GetServerHost added in v0.2.11

func (hub *Hub) GetServerHost() string

func (*Hub) GetServerPort added in v0.2.11

func (hub *Hub) GetServerPort() int

func (*Hub) GetServers added in v0.2.11

func (hub *Hub) GetServers() []builder.Address

func (*Hub) GetUserClient added in v0.2.11

func (hub *Hub) GetUserClient(session *Session) *Client

func (*Hub) Handler added in v0.2.11

func (hub *Hub) Handler(ctx context.Context, info ConnectInfo, w http.ResponseWriter, r *http.Request) error

func (*Hub) InClient added in v0.2.11

func (hub *Hub) InClient(client *Client) (ok bool)

func (*Hub) Init added in v0.2.11

func (hub *Hub) Init(cfg Config)

func (*Hub) IsLocalAddress added in v0.2.11

func (hub *Hub) IsLocalAddress(server string) bool

func (*Hub) OnClose added in v0.2.17

func (hub *Hub) OnClose(ctx context.Context)

func (*Hub) OnLogin added in v0.2.11

func (hub *Hub) OnLogin(ctx context.Context, log LogInfo)

OnLogin 用户登录

func (*Hub) OnLogout added in v0.2.11

func (hub *Hub) OnLogout(ctx context.Context, log LogInfo)

OnLogout 用户登出

func (*Hub) RateLimit added in v0.2.11

func (hub *Hub) RateLimit(session Session, version string) bool

func (*Hub) Receive added in v0.2.11

func (hub *Hub) Receive(ctx context.Context, from *Session, to *Session, ev *Event) (err error)

func (*Hub) ReceiveAll added in v0.2.11

func (hub *Hub) ReceiveAll(ctx context.Context, from *Session, to *Session, ev *Event) (err error)

func (*Hub) SendChat added in v0.2.11

func (hub *Hub) SendChat(ctx context.Context, from *Session, ev *Event, option chat.Option, handler func()) error

func (*Hub) SendToAllUser added in v0.2.11

func (hub *Hub) SendToAllUser(ctx context.Context, from *Session, to *Session, ev *Event, data interface{})

SendToAllUser 给全体用户发消息 data 用户定义的数据结构(内部使用)

func (*Hub) SendToLocalAppId added in v0.2.11

func (hub *Hub) SendToLocalAppId(ctx context.Context, from *Session, to *Session, ev *Event, data interface{})

SendToLocalAppId 给本地 指定的客户端appid 送消息到, 除了userId data 用户定义的数据结构(内部使用)

func (*Hub) SendToLocalUser added in v0.2.11

func (hub *Hub) SendToLocalUser(ctx context.Context, from *Session, to *Session, ev *Event) (error, bool)

SendToLocalUser 给本机指定用户发送消息

func (*Hub) SendToRemote added in v0.2.11

func (hub *Hub) SendToRemote(ctx context.Context, from *Session, to *Session, ev *Event)

SendToRemote 发送到远端

func (*Hub) SendToRemoteAppId added in v0.2.11

func (hub *Hub) SendToRemoteAppId(ctx context.Context, addr string, from *Session, to *Session, ev *Event)

func (*Hub) SendToRemoteUser added in v0.2.11

func (hub *Hub) SendToRemoteUser(ctx context.Context, from *Session, to *Session, ev *Event) error

func (*Hub) SendToUser added in v0.2.11

func (hub *Hub) SendToUser(ctx context.Context, from *Session, to *Session, ev *Event) error

SendToUser 给指定在线用户发送消息

func (*Hub) Source added in v0.2.11

func (hub *Hub) Source() string

func (*Hub) StatusChanged added in v0.2.11

func (hub *Hub) StatusChanged(ctx context.Context, us Status)

func (*Hub) SyncToRemoteOnly added in v0.2.11

func (hub *Hub) SyncToRemoteOnly(ctx context.Context, from *Session, to *Session, ev *Event)

SyncToRemoteOnly 仅仅只同步到远端

func (*Hub) UnInit added in v0.2.11

func (hub *Hub) UnInit()

type IAmMemberFunc

type IAmMemberFunc func(user *Session, iAmMember bool) error

IAmMemberFunc 是否是群成员, iAmMember= true 是成员

type LogInfo added in v0.2.1

type LogInfo struct {
	Session
	TimeAt int64
	Client *Client
}

LogInfo 用户,登录/登出

type MemberFunc

type MemberFunc func(groupId int64, user *Session) error

type MessageMQ added in v0.2.11

type MessageMQ struct {
	Cmd     int    `json:"cmd"`
	Topic   string `json:"topic"`   // SubscribeMQ OR UnSubscribeMQ 可以多个topic, 以逗号分隔
	Content string `json:"content"` // 具体内容
	// contains filtered or unexported fields
}

type Mq added in v0.2.11

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

func (*Mq) Process added in v0.2.11

func (mq *Mq) Process(c *Client, req *EventReq) (interface{}, error)

func (*Mq) Receive added in v0.2.11

func (mq *Mq) Receive(ctx context.Context, from *Session, ev *Event)

type OnLineList added in v0.2.21

type OnLineList struct {
	Count int       `json:"count"`
	List  []*Online `json:"list,omitempty"`
}

type Online

type Online struct {
	ID            string `json:"id"`
	AppId         string `json:"appId"`
	ClientIp      string `json:"clientIp"`   // 客户端Ip
	ClientPort    string `json:"clientPort"` // 客户端端口
	RemoteIp      string `json:"remoteIp"`   //用户远程IP
	Host          string `json:"host"`       // 用户所在的服务器ip
	Account       string `json:"account"`
	UserId        uint64 `json:"userId"`
	Port          int    `json:"port"` // 用户所在的服务器端口
	Plat          int32  `json:"plat"`
	LoginTime     int64  `json:"loginTime"`     // 用户上次登录时间
	HeartbeatTime int64  `json:"heartbeatTime"` // 用户上次心跳时间
	LogOutTime    int64  `json:"logOutTime"`    // 用户退出登录的时间
	IsOffline     bool   `json:"isOffline"`     // 是否离线
}

func (*Online) Heartbeat

func (u *Online) Heartbeat(currentTime int64)

func (*Online) IsLocal

func (u *Online) IsLocal(localIp string, localPort int) bool

IsLocal 用户是否在本台机器上

func (*Online) IsOnline

func (u *Online) IsOnline(heartCheck func(heartbeat int64) bool) bool

func (*Online) LogIn

func (u *Online) LogIn(currentTime int64)

func (*Online) LogOut

func (u *Online) LogOut(currentTime int64)

func (*Online) String

func (u *Online) String() string

func (*Online) ToSession added in v0.2.21

func (u *Online) ToSession() Session

type Option

type Option func(hub *Hub)

func WithChatGroupOption added in v0.2.11

func WithChatGroupOption(group chat.Group) Option

WithChatGroupOption 群管理及群聊

func WithChatOption added in v0.2.15

func WithChatOption(chat chat.Chat) Option

WithChatOption 聊天信息保存

func WithDiscoveryClientOption added in v0.2.15

func WithDiscoveryClientOption(client discoveryservice.Client) Option

WithDiscoveryClientOption 分布式支持

func WithRpcClientOption added in v0.2.11

func WithRpcClientOption(rpc rpc.Client) Option

WithRpcClientOption 外部服务接用

func WithUseMQOption added in v0.2.11

func WithUseMQOption() Option

WithUseMQOption MQ支持

func WithUserMgrOption added in v0.2.11

func WithUserMgrOption(user User) Option

WithUserMgrOption 用户管理

func WithWorkerNumOption added in v0.2.13

func WithWorkerNumOption(work int) Option

WithWorkerNumOption 配置工作线程

type Query added in v0.3.8

type Query interface {
	Search(client *Client) int
}

type QueryFunc added in v0.3.8

type QueryFunc func(client *Client) int

func (QueryFunc) Search added in v0.3.8

func (f QueryFunc) Search(client *Client) int

type ReqHead

type ReqHead struct {
	Source  string        `json:"source"`
	Version string        `json:"version"`
	SeqId   string        `json:"seqId"`
	ReqAt   int64         `json:"timeAt"` //客户端或服务器的时间
	RecvAt  int64         `json:"-"`      //服务器收到的时间
	TimeOut time.Duration `json:"-"`
}

func (*ReqHead) GetRecvAt

func (h *ReqHead) GetRecvAt() int64

GetRecvAt request.HeadV2 interface

func (*ReqHead) GetReqAt

func (h *ReqHead) GetReqAt() int64

GetReqAt request.HeadV2 interface

func (*ReqHead) GetSeqId

func (h *ReqHead) GetSeqId() string

GetSeqId request.Head interface

func (*ReqHead) GetSource

func (h *ReqHead) GetSource() string

GetSource request.Head interface

func (*ReqHead) GetTimeOut

func (h *ReqHead) GetTimeOut() time.Duration

GetTimeOut request.HeadV2 interface

func (*ReqHead) GetVersion

func (h *ReqHead) GetVersion() string

GetVersion request.Head interface

func (*ReqHead) SetSource

func (h *ReqHead) SetSource(source string)

SetSource request.HeadV2 interface

func (*ReqHead) SetTimeOut

func (h *ReqHead) SetTimeOut(duration time.Duration)

SetTimeOut request.HeadV2 interface

type ResHead

type ResHead struct {
	result.Result
	Version  string `json:"version"`            //版本,请求者版本
	Source   string `json:"source,omitempty"`   //请求源,可以请求者填写
	SeqId    string `json:"seqId,omitempty"`    //请求序号,由请求者定义,服务器原路返回
	TimeAt   int64  `json:"timeAt,omitempty"`   //服务收到请求的时间(ms)
	DiffAt   int64  `json:"diffAt,omitempty"`   //客户端与服务端时间差值(ms)
	SpendAt  int64  `json:"spendAt,omitempty"`  //从服务收到请求到响应完成,所花的时长(ms)
	ServerAt int64  `json:"serverAt,omitempty"` //服务器时间,豪秒,用于检验对时(ms)
	LogId    string `json:"logId,omitempty"`
}

func NewResHead

func NewResHead(source string, res result.Result) ResHead

type Session

type Session struct {
	AppId      string `form:"appId" binding:"required" json:"appId" yaml:"appId" url:"appId"`
	Account    string `form:"account" json:"account" yaml:"account" url:"account"`
	UserId     uint64 `form:"userId" json:"userId,omitempty" yaml:"userId,omitempty" url:"userId,omitempty"`
	ClientId   uint64 `form:"clientId" json:"clientId,omitempty" yaml:"clientId,omitempty" url:"clientId,omitempty"`         //客户端id
	ClientType int32  `form:"clientType" json:"clientType,omitempty" yaml:"clientType,omitempty" url:"clientType,omitempty"` //客户端类型
	Plat       int32  `form:"plat" json:"plat" yaml:"plat" url:"plat"`
	OrgId      int32  `form:"orgId" json:"orgId,omitempty" yaml:"orgId,omitempty" url:"orgId,omitempty"`             //所属组织
	TenantId   int32  `form:"tenantId" json:"tenantId,omitempty" yaml:"tenantId,omitempty" url:"tenantId,omitempty"` //租户id
	Ignore     int32  `form:"ignore" json:"ignore,omitempty" yaml:"ignore,omitempty" url:"ignore,omitempty"`
}

func PBSessionToSession

func PBSessionToSession(session *pb.Session) Session

func PBUserToSession

func PBUserToSession(u *pb.User) Session

func (*Session) Equal added in v0.2.2

func (s *Session) Equal(c *Session) bool

func (*Session) EqualAccount added in v0.2.2

func (s *Session) EqualAccount(c *Session) bool

func (*Session) EqualAppId added in v0.2.2

func (s *Session) EqualAppId(session *Session) bool

func (*Session) EqualPlat added in v0.2.2

func (s *Session) EqualPlat(session *Session) bool

func (*Session) EqualUserId added in v0.2.2

func (s *Session) EqualUserId(c *Session) bool

func (*Session) IgnoreBit added in v0.2.11

func (s *Session) IgnoreBit(f int32) bool

func (*Session) IsValid added in v0.1.30

func (s *Session) IsValid() bool

func (*Session) String

func (s *Session) String() string

type Status

type Status struct {
	Session
	LoginTime  int64  `json:"-"`
	TimeAt     int64  `json:"timeAt"`
	Status     int32  `json:"status"`
	Desc       string `json:"desc"`
	TraceId    string `json:"-"`
	Addr       string `json:"-"`
	RemoteAddr string `json:"-"`
}

func (*Status) String

func (s *Status) String() string

type User

type User interface {
	SetSupportApp(apps []App)
	NextSupportApp(fn func(app App) bool)
	ExistSupportApp(app App) bool
	HeartbeatTimeout() int64
	GetUserKey(session *Session) string
	GetUserOnline(session *Session, opt ...option.Option) (*Online, error)
	// SetUserOnline 写到redis中
	SetUserOnline(session *Session, online *Online) error
	RemoveUserOnline(session *Session) error
	IsUserOnline(session *Session) (bool, error)

	GetAllOnline(cc *Copy, session *Session, opt ...option.Option) error

	//UserStatusChanged 通知基它服务有变化
	UserStatusChanged(status *Status, opt ...option.Option)
}

type UserList

type UserList struct {
	Count int       `json:"count"`
	List  []Session `json:"list,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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