Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdea25a

Browse files
committed
评论支持翻页
1 parent ade1eb7 commit bdea25a

File tree

18 files changed

+1233
-365
lines changed

18 files changed

+1233
-365
lines changed

src/db/conn.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func init() {
3535
if err = initEngine(); err != nil {
3636
panic(err)
3737
}
38+
39+
// 测试数据库连接是否 OK
40+
if err = MasterDB.Ping(); err != nil {
41+
panic(err)
42+
}
3843
}
3944

4045
var (
@@ -83,9 +88,7 @@ func TestDB() error {
8388
}
8489

8590
// 初始化 MasterDB
86-
Init()
87-
88-
return nil
91+
return Init()
8992
}
9093

9194
func Init() error {

src/global/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
)
3737

3838
const (
39-
DefaultCDNHttp = "http://studygolang.qiniudn.com/"
39+
DefaultCDNHttp = "http://test.static.studygolang.com/"
4040
DefaultCDNHttps = "https://static.studygolang.com/"
4141
)
4242

src/http/http.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"global"
1313
"html/template"
1414
"logic"
15+
"math"
1516
"math/rand"
1617
"model"
1718
"net/http"
@@ -128,6 +129,9 @@ var funcMap = template.FuncMap{
128129

129130
return num1 % num2
130131
},
132+
"divide": func(num1, num2 int) int {
133+
return int(math.Ceil(float64(num1) / float64(num2)))
134+
},
131135
"explode": func(s, sep string) []string {
132136
return strings.Split(s, sep)
133137
},
@@ -175,6 +179,19 @@ var funcMap = template.FuncMap{
175179

176180
return uri
177181
},
182+
"genList": func(n int, steps ...int) []int {
183+
step := 1
184+
if len(steps) > 0 {
185+
step = steps[0]
186+
}
187+
num := int(math.Ceil(float64(n) / float64(step)))
188+
nums := make([]int, num)
189+
for i := 0; i < num; i++ {
190+
nums[i] = i + 1
191+
}
192+
193+
return nums
194+
},
178195
}
179196

180197
func tplInclude(file string, dot map[string]interface{}) template.HTML {
@@ -380,6 +397,9 @@ func executeTpl(ctx echo.Context, tpl *template.Template, data map[string]interf
380397

381398
data["setting"] = logic.WebsiteSetting
382399

400+
// 评论每页显示多少个
401+
data["cmt_per_num"] = logic.CommentPerNum
402+
383403
// 记录处理时间
384404
data["resp_time"] = time.Since(ctx.Get("req_start_time").(time.Time))
385405

src/logic/comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (self CommentLogic) FindObjComments(ctx context.Context, objid, objtype int
6464
return
6565
}
6666

67-
const CommentPerNum = 5
67+
const CommentPerNum = 50
6868

6969
// FindObjectComments 获得某个对象的所有评论(新版)
7070
func (self CommentLogic) FindObjectComments(ctx context.Context, objid, objtype, p int) (commentList []*model.Comment, replyComments []*model.Comment, pageNum int, err error) {

0 commit comments

Comments
 (0)