Skip to content

Commit 6b7bb44

Browse files
committed
add golint
1 parent de62f4f commit 6b7bb44

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: lint gate master notice store
22

3-
LDFLAGS += -X "github.com/dearcode/candy/util.BUILD_TIME=$(shell date +%s)"
4-
LDFLAGS += -X "github.com/dearcode/candy/util.BUILD_VERSION=$(shell git rev-parse HEAD)"
3+
LDFLAGS += -X "github.com/dearcode/candy/util.BuildTime=$(shell date)"
4+
LDFLAGS += -X "github.com/dearcode/candy/util.BuildVersion=$(shell git rev-parse HEAD)"
55

66
golint:
77
go get github.com/golang/lint/golint
@@ -19,6 +19,8 @@ meta:
1919
lint: golint
2020
golint gate/
2121
golint store/
22+
golint notice/
23+
golint util/
2224

2325
clean:
2426
@rm -rf bin

notice/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (n *Notifer) Subscribe(c context.Context, req *meta.SubscribeRequest) (*met
4949
return &meta.SubscribeResponse{}, nil
5050
}
5151

52-
// Unsubscribe unsubscribe a Notifer.
52+
// UnSubscribe unsubscribe a Notifer.
5353
func (n *Notifer) UnSubscribe(_ context.Context, req *meta.UnSubscribeRequest) (*meta.UnSubscribeResponse, error) {
5454
n.broker.UnSubscribe(req.ID)
5555
return &meta.UnSubscribeResponse{}, nil

util/common.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,60 @@ package util
33
import (
44
"crypto/md5"
55
"fmt"
6-
"strconv"
76
"time"
87
)
98

109
var (
11-
BUILD_TIME = ""
12-
BUILD_VERSION = ""
10+
// BuildTime 编译时间.
11+
BuildTime = ""
12+
// BuildVersion git版本.
13+
BuildVersion = ""
1314
)
1415

1516
const (
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 输出当前程序编译信息.
3648
func 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.
4355
func 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.
4760
func 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.
5569
func 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.
6378
func MD5(data []byte) []byte {
6479
hash := md5.New()
6580
hash.Write(data)

util/master.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
"github.com/dearcode/candy/meta"
99
)
1010

11+
// Master 连接master服务.
1112
type Master struct {
1213
client meta.MasterClient
1314
}
1415

16+
// NewMaster 返回master client.
1517
func NewMaster(host string) (*Master, error) {
1618
conn, err := grpc.Dial(host, grpc.WithInsecure(), grpc.WithTimeout(NetworkTimeout))
1719
if err != nil {
@@ -20,6 +22,7 @@ func NewMaster(host string) (*Master, error) {
2022
return &Master{client: meta.NewMasterClient(conn)}, nil
2123
}
2224

25+
// NewID 生成新ID.
2326
func (m *Master) NewID() (int64, error) {
2427
resp, err := m.client.NewID(context.Background(), &meta.NewIDRequest{})
2528
if err != nil {

util/notice.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"github.com/dearcode/candy/util/log"
1010
)
1111

12+
// Notice 连接notice服务.
1213
type Notice struct {
1314
client meta.NoticeClient
1415
}
1516

17+
// NewNotice 返回notice client.
1618
func NewNotice(host string) (*Notice, error) {
1719
log.Debugf("dial host:%v", host)
1820
conn, err := grpc.Dial(host, grpc.WithInsecure(), grpc.WithTimeout(NetworkTimeout))

0 commit comments

Comments
 (0)