@@ -3,47 +3,60 @@ package util
33import (
44 "crypto/md5"
55 "fmt"
6- "strconv"
76 "time"
87)
98
109var (
11- BUILD_TIME = ""
12- BUILD_VERSION = ""
10+ // BuildTime 编译时间.
11+ BuildTime = ""
12+ // BuildVersion git版本.
13+ BuildVersion = ""
1314)
1415
1516const (
16- UserDBPath = "user"
17+ // UserDBPath 用户数据库位置.
18+ UserDBPath = "user"
19+ // MessageDBPath 消息数据库位置.
1720 MessageDBPath = "message"
18- GroupDBPath = "group"
21+ // GroupDBPath 群组数据库位置.
22+ GroupDBPath = "group"
1923
2024 // FileBlockPath 块文件存储位置
2125 FileBlockPath = "file_block"
2226 // FileDBPath 文件索引存储位置
2327 FileDBPath = "file"
2428
29+ // MessageLogDBPath 消息记录数据库位置.
2530 MessageLogDBPath = "message_log"
2631
27- UserMessagePrefix = int64 (0 )
32+ // UserMessagePrefix 用户消息前缀.
33+ UserMessagePrefix = int64 (0 )
34+ // UserLastMessagePrefix 用户最后一个消息ID.
2835 UserLastMessagePrefix = int64 (1 )
29- UserGroupPrefix = int64 (2 )
30- UserFriendPrefix = int64 (3 )
31- UserIDPrefix = int64 (4 )
36+ // UserGroupPrefix 用户组前缀.
37+ UserGroupPrefix = int64 (2 )
38+ // UserFriendPrefix 用户好友前缀.
39+ UserFriendPrefix = int64 (3 )
40+ // UserIDPrefix 用户前缀.
41+ UserIDPrefix = int64 (4 )
3242
43+ // NetworkTimeout 超时.
3344 NetworkTimeout = time .Second * 3
3445)
3546
47+ // PrintVersion 输出当前程序编译信息.
3648func PrintVersion () {
3749 fmt .Printf ("Candy\n " )
38- sec , _ := strconv .ParseInt (BUILD_TIME , 10 , 32 )
39- fmt .Printf ("Build Time: %s\n " , time .Unix (sec , 0 ).Format ("2006-01-02 15:04:05" ))
40- fmt .Printf ("Git Version: %s\n " , BUILD_VERSION )
50+ fmt .Printf ("Build Time: %s\n " , BuildTime )
51+ fmt .Printf ("Git Version: %s\n " , BuildVersion )
4152}
4253
54+ // EncodeInt64 编码int64到[]byte.
4355func EncodeInt64 (v int64 ) []byte {
4456 return []byte {byte (v >> 56 ), byte (v >> 48 ), byte (v >> 40 ), byte (v >> 32 ), byte (v >> 24 ), byte (v >> 16 ), byte (v >> 8 ), byte (v )}
4557}
4658
59+ // DecodeInt64 解码[]byte到int64.
4760func DecodeInt64 (b []byte ) int64 {
4861 if len (b ) < 8 {
4962 return 0
@@ -52,6 +65,7 @@ func DecodeInt64(b []byte) int64 {
5265 return int64 (b [0 ])<< 56 + int64 (b [1 ])<< 48 + int64 (b [2 ])<< 40 + int64 (b [3 ])<< 32 + int64 (b [4 ])<< 24 + int64 (b [5 ])<< 16 + int64 (b [6 ])<< 8 + int64 (b [7 ])
5366}
5467
68+ // EncodeKey 编码int64数组到[]byte.
5569func EncodeKey (args ... int64 ) []byte {
5670 var key []byte
5771 for _ , v := range args {
@@ -60,6 +74,7 @@ func EncodeKey(args ...int64) []byte {
6074 return key
6175}
6276
77+ // MD5 计算md5.
6378func MD5 (data []byte ) []byte {
6479 hash := md5 .New ()
6580 hash .Write (data )
0 commit comments