From 56e314e64d77e64238d21251c2f077a5497cd621 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 19 May 2018 00:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgfile.MTimeMillisecond?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=AE=8C=E5=96=84gpage=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=88=86=E9=A1=B5=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/os/gfile/gfile.go | 4 +--- geg/other/test.go | 12 +++++++----- geg/util/gpage/gpage_custom1.go | 26 +++++++++++++------------- geg/util/gpage/gpage_custom2.go | 26 +++++++++++++------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index 286571bdc..7275f6729 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -126,9 +126,7 @@ func MTimeMillisecond(path string) int64 { if e != nil { return 0 } - seconds := f.ModTime().Unix() - nanoSeconds := f.ModTime().Nanosecond() - return seconds*1000 + int64(nanoSeconds/1000000) + return int64(f.ModTime().Nanosecond()/1000000) } // 文件大小(bytes) diff --git a/geg/other/test.go b/geg/other/test.go index 085a3d00b..4b5623370 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -8,11 +8,13 @@ import ( ) func main() { - - gtime.SetInterval(10*time.Millisecond, func() bool { - path := "./temp.txt" - gfile.PutBinContentsAppend(path, []byte("1")) - fmt.Println(gfile.MTimeMillisecond(path)) + file, err := gfile.Open("/home/john/Documents/temp.txt") + fmt.Println(err) + gtime.SetInterval(time.Second, func() bool { + if s, e := file.Stat(); e == nil { + fmt.Println(s.ModTime().Unix()) + fmt.Println(gfile.MTime("/home/john/Documents/temp.txt")) + } return true }) diff --git a/geg/util/gpage/gpage_custom1.go b/geg/util/gpage/gpage_custom1.go index 230617411..bcdbd15dc 100644 --- a/geg/util/gpage/gpage_custom1.go +++ b/geg/util/gpage/gpage_custom1.go @@ -3,28 +3,28 @@ package main import ( "gitee.com/johng/gf/g" "gitee.com/johng/gf/g/os/gview" + "gitee.com/johng/gf/g/util/gstr" "gitee.com/johng/gf/g/net/ghttp" "gitee.com/johng/gf/g/util/gpage" ) -// 自定义分页名称 -func pageContent(page *gpage.Page) string { - page.NextPageTag = "NextPage" - page.PrevPageTag = "PrevPage" - page.FirstPageTag = "HomePage" - page.LastPageTag = "LastPage" - pageStr := page.FirstPage() - pageStr += page.PrevPage() - pageStr += page.PageBar("current-page") - pageStr += page.NextPage() - pageStr += page.LastPage() - return pageStr +// 分页标签使用li标签包裹 +func wrapContent(page *gpage.Page) string { + content := page.GetContent(4) + content = gstr.ReplaceByMap(content, map[string]string { + "" : "/span>", + "" : "/a>", + }) + return "
    " + content + "
" } func main() { s := ghttp.GetServer() s.BindHandler("/page/custom1/*page", func(r *ghttp.Request){ page := gpage.New(100, 10, r.Get("page"), r.URL.String(), r.Router.Uri) + content := wrapContent(page) buffer, _ := gview.ParseContent(` @@ -38,7 +38,7 @@ func main() { `, g.Map{ - "page" : gview.HTML(pageContent(page)), + "page" : gview.HTML(content), }) r.Response.Write(buffer) }) diff --git a/geg/util/gpage/gpage_custom2.go b/geg/util/gpage/gpage_custom2.go index 1b908b61d..19fde6d1e 100644 --- a/geg/util/gpage/gpage_custom2.go +++ b/geg/util/gpage/gpage_custom2.go @@ -3,28 +3,28 @@ package main import ( "gitee.com/johng/gf/g" "gitee.com/johng/gf/g/os/gview" - "gitee.com/johng/gf/g/util/gstr" "gitee.com/johng/gf/g/net/ghttp" "gitee.com/johng/gf/g/util/gpage" ) -// 分页标签使用li标签包裹 -func wrapContent(page *gpage.Page) string { - content := page.GetContent(4) - content = gstr.ReplaceByMap(content, map[string]string { - "" : "/span>", - "" : "/a>", - }) - return "
    " + content + "
" +// 自定义分页名称 +func pageContent(page *gpage.Page) string { + page.NextPageTag = "NextPage" + page.PrevPageTag = "PrevPage" + page.FirstPageTag = "HomePage" + page.LastPageTag = "LastPage" + pageStr := page.FirstPage() + pageStr += page.PrevPage() + pageStr += page.PageBar("current-page") + pageStr += page.NextPage() + pageStr += page.LastPage() + return pageStr } func main() { s := ghttp.GetServer() s.BindHandler("/page/custom2/*page", func(r *ghttp.Request){ page := gpage.New(100, 10, r.Get("page"), r.URL.String(), r.Router.Uri) - content := wrapContent(page) buffer, _ := gview.ParseContent(` @@ -38,7 +38,7 @@ func main() { `, g.Map{ - "page" : gview.HTML(content), + "page" : gview.HTML(pageContent(page)), }) r.Response.Write(buffer) })