util

package
v0.0.0-...-17d8d8c Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2018 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserDBPath 用户数据库位置.
	UserDBPath = "user"
	// MessageDBPath 消息数据库位置.
	MessageDBPath = "message"
	// GroupDBPath 群组数据库位置.
	GroupDBPath = "group"

	// FileBlockPath 块文件存储位置
	FileBlockPath = "file_block"
	// FileDBPath 文件索引存储位置
	FileDBPath = "file"

	// MessageLogDBPath 消息记录数据库位置.
	MessageLogDBPath = "message_log"

	// UserMessagePrefix 用户消息前缀.
	UserMessagePrefix = int64(0)

	//GroupAdminPrefix 群管理员
	GroupAdminPrefix = int64(0)
	//GroupMemberPrefix 群成员
	GroupMemberPrefix = int64(1)
	//GroupInvitePrefix 群邀请消息
	GroupInvitePrefix = int64(2)
	//GroupApplyPrefix 申请入群消息
	GroupApplyPrefix = int64(3)

	// UserLastMessagePrefix 用户最后一个消息ID.
	UserLastMessagePrefix = int64(1)
	// UserGroupPrefix 用户组前缀.
	UserGroupPrefix = int64(2)
	// UserFriendPrefix 用户好友前缀.
	UserFriendPrefix = int64(3)
	// UserIDPrefix 用户前缀.
	UserIDPrefix = int64(4)
	// UserRecentContactPrefix 最近联系人或群前缀.
	UserRecentContactPrefix = int64(5)

	// NetworkTimeout 超时.
	NetworkTimeout = time.Second * 3
)
View Source
const (
	// ErrorOK 成功
	ErrorOK = 0
	// ErrorFailure 未知错误
	ErrorFailure = 1
	// ErrorUserNameFormat 用户名格式错误
	ErrorUserNameFormat = 1000
	// ErrorUserNameLen 用户名长度错误
	ErrorUserNameLen = 1001
	// ErrorUserPasswdFormat 用户密码格式错误
	ErrorUserPasswdFormat = 1010
	// ErrorUserPasswdLen 用户密码长度错误
	ErrorUserPasswdLen = 1011
	// ErrorUserNickFormat 昵称格式错误
	ErrorUserNickFormat = 1020
	// ErrorUserNickLen 昵称长度错误
	ErrorUserNickLen = 1021
	// ErrorGetSession 获取回话失败
	ErrorGetSession = 1030
	// ErrorMasterNewID 生成ID失败
	ErrorMasterNewID = 1031
	// ErrorRegister 注册失败
	ErrorRegister = 1032
	// ErrorOffline 已经离线
	ErrorOffline = 1033
	// ErrorUpdateUserInfo 更新用户信息失败
	ErrorUpdateUserInfo = 1034
	// ErrorUpdateUserPasswd 更新用户密码失败
	ErrorUpdateUserPasswd = 1035
	// ErrorGetUserInfo 获取用户信息失败
	ErrorGetUserInfo = 1036
	// ErrorAuth 用户认证失败(提示用户名或密码错误)
	ErrorAuth = 1037
	// ErrorSubscribe 消息订阅失败
	ErrorSubscribe = 1038
	// ErrorUnSubscribe 取消消息订阅失败
	ErrorUnSubscribe = 1039
	// ErrorNewMessage 发送消息失败
	ErrorNewMessage = 1040
	// ErrorFriendSelf 不能添加自己为好友
	ErrorFriendSelf = 1041
	// ErrorAddFriend 添加好友失败
	ErrorAddFriend = 1042
	// ErrorGetOnlineSession 用户不在线
	ErrorGetOnlineSession = 1043
	// ErrorLoadFriendList 加载好友列表失败
	ErrorLoadFriendList = 1044
	// ErrorFindUser 查找用户失败
	ErrorFindUser = 1045
	// ErrorCreateGroup 创建分组失败
	ErrorCreateGroup = 1046
	// ErrorLoadGroup 加载群组列表失败
	ErrorLoadGroup = 1047
	// ErrorUploadFile 上传文件失败
	ErrorUploadFile = 1048
	// ErrorCheckFile 文件检查失败
	ErrorCheckFile = 1049
	// ErrorDownloadFile 下载文件失败
	ErrorDownloadFile = 1050
	// ErrorLoadMessage 加载消息列表失败
	ErrorLoadMessage = 1051
	// ErrorUpdateSignature 更新签名失败
	ErrorUpdateSignature = 1052
)
View Source
const (
	// EtcdMasterKey master key prefix.
	EtcdMasterKey = "/master"
	// EtcdMasterAddrKey master addr key.
	EtcdMasterAddrKey = EtcdMasterKey + "/addr"
)

Variables

View Source
var (
	// GitTime git log中记录的提交时间.
	GitTime = ""
	// GitMessage git log 中记录的提交信息.
	GitMessage = ""
)
View Source
var (
	// ErrInvalidContext 从context中解析客户端地址时出错.
	ErrInvalidContext = errors.New("invalid context")
)
View Source
var (
	//ErrMasterNotFound 未找到master.
	ErrMasterNotFound = errors.New("etcd master host not found")
)
View Source
var (
	//ErrRegionNotFound region not exist.
	ErrRegionNotFound = errors.New("region not found")
)

Functions

func ContextGet

func ContextGet(ctx context.Context, key string) (string, error)

ContextGet get value from context's metadata.

func ContextSet

func ContextSet(ctx context.Context, key, val string) context.Context

ContextSet set value to context's metadata.

func DecodeInt64

func DecodeInt64(b []byte) int64

DecodeInt64 解码[]byte到int64.

func EncodeInt64

func EncodeInt64(v int64) []byte

EncodeInt64 编码int64到[]byte.

func EncodeKey

func EncodeKey(args ...int64) []byte

EncodeKey 编码int64数组到[]byte.

func MD5

func MD5(data []byte) []byte

MD5 计算md5.

func PrintVersion

func PrintVersion()

PrintVersion 输出当前程序编译信息.

func Split

func Split(s, sep string) []string

Split 如果s为空字符串返回空数组

Types

type EtcdClient

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

EtcdClient etcd client.

func NewEtcdClient

func NewEtcdClient(addrs []string) (*EtcdClient, error)

NewEtcdClient new etcd client.

func (*EtcdClient) CAS

func (e *EtcdClient) CAS(cmpKey, cmpValue, key, value string) error

CAS put value to etcd.

func (*EtcdClient) CampaignLeader

func (e *EtcdClient) CampaignLeader(key, value string) (<-chan bool, chan<- struct{})

CampaignLeader 竞争leader 返回状态只读的chan与关闭只写的chan state如果状态变化则通知, stop外部关闭则停止keepalive

func (*EtcdClient) Close

func (e *EtcdClient) Close()

Close 关闭客户端

func (*EtcdClient) Get

func (e *EtcdClient) Get(key string) (string, error)

Get get value from etcd.

func (*EtcdClient) WaitKeyDelete

func (e *EtcdClient) WaitKeyDelete(key string)

WaitKeyDelete 等待Key被删除

func (*EtcdClient) WaitKeyPut

func (e *EtcdClient) WaitKeyPut(key string)

WaitKeyPut 等待Key被修改

type MasterClient

type MasterClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MasterClient 连接master服务.

func NewMasterClient

func NewMasterClient(host string, etcdAddrs []string) (*MasterClient, error)

NewMasterClient 返回master client.

func (*MasterClient) NewID

func (m *MasterClient) NewID() (int64, error)

NewID 生成新ID.

func (*MasterClient) RegionGet

func (m *MasterClient) RegionGet(host string) ([]meta.Region, error)

RegionGet 根据host获取region

type NotiferClient

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

NotiferClient 连接Notifer服务.

func NewNotiferClient

func NewNotiferClient(host string) (*NotiferClient, error)

NewNotiferClient 返回NotiferClient client.

func (*NotiferClient) Push

func (n *NotiferClient) Push(msg meta.PushMessage, ids ...meta.PushID) error

Push 为store提供调用Notifer发推送消息

func (*NotiferClient) RegionSet

func (n *NotiferClient) RegionSet(begin, end int32) error

RegionSet 为master提供,调用Notifer修改所负责的region

func (*NotiferClient) Stop

func (n *NotiferClient) Stop()

Stop 关闭连接

func (*NotiferClient) Subscribe

func (n *NotiferClient) Subscribe(id int64, device string, token int64, host string) error

Subscribe 为gate提供,调用Notifer订阅消息

func (*NotiferClient) UnSubscribe

func (n *NotiferClient) UnSubscribe(id int64, device, host string, sid int64) error

UnSubscribe 为gate提供,调用Notifer取消订阅消息

type Regions

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

Regions 保存region的路由信息.

func NewRegions

func NewRegions(ops ...RegionsOption) (*Regions, error)

NewRegions 初始化llrb,map.

func (*Regions) Dump

func (r *Regions) Dump() []meta.Region

Dump 导出region

func (*Regions) Get

func (r *Regions) Get(id int64) (meta.Region, bool)

Get 根据ID获取对应的region信息

func (*Regions) GetByHost

func (r *Regions) GetByHost(host string) (meta.Region, error)

GetByHost 根据host获取对应的region信息.

func (*Regions) Marshal

func (r *Regions) Marshal() (b []byte, e error)

Marshal 导出json格式数据

func (*Regions) Max

func (r *Regions) Max() (meta.Region, error)

Max 当前跨度最大的节点

func (*Regions) Merge

func (r *Regions) Merge(from, to string) error

Merge 合并节点,合并当前删除的节点到前一个节点

func (*Regions) Next

func (r *Regions) Next(host string) (self meta.Region, next meta.Region, err error)

Next 返回当前节点的下一个节点

func (*Regions) Split

func (r *Regions) Split(from, to string) (meta.Region, error)

Split 添加一个节点并分割相对大的节点.

type RegionsOption

type RegionsOption func(*Regions) error

RegionsOption Regions option.

func RegionsWithHosts

func RegionsWithHosts(hosts string) RegionsOption

RegionsWithHosts 初始化hosts

type Retry

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

Retry 自带sleep的重试.

func NewRetry

func NewRetry(ops ...RetryOption) *Retry

NewRetry new retry.

func (*Retry) Attempts

func (r *Retry) Attempts() int

Attempts current attempt times.

func (*Retry) Next

func (r *Retry) Next()

Next wait sleep.

func (*Retry) Reset

func (r *Retry) Reset()

Reset attempts.

func (*Retry) Valid

func (r *Retry) Valid() bool

Valid check max attempts

type RetryOption

type RetryOption func(*Retry)

RetryOption retry option.

func RetryAttemptMax

func RetryAttemptMax(v int) RetryOption

RetryAttemptMax 设置最大重试次数, 0 为一直重试

func RetryDurationMax

func RetryDurationMax(v time.Duration) RetryOption

RetryDurationMax 最小间隔时间

func RetryDurationMin

func RetryDurationMin(v time.Duration) RetryOption

RetryDurationMin 最小间隔时间

type Version

type Version struct {
}

Version 版本信息.

func (*Version) GET

func (v *Version) GET(w http.ResponseWriter, r *http.Request)

GET 输出当前应用版本信息.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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