修复gfile.MTimeMillisecond方法,完善gpage自定义分页示例

This commit is contained in:
John
2018-05-19 00:40:55 +08:00
parent f702039a06
commit 56e314e64d
4 changed files with 34 additions and 34 deletions

View File

@ -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)

View File

@ -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
})

View File

@ -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" : "<li><span",
"/span>" : "/span></li>",
"<a" : "<li><a",
"/a>" : "/a></li>",
})
return "<ul>" + content + "</ul>"
}
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(`
<html>
<head>
@ -38,7 +38,7 @@ func main() {
</body>
</html>
`, g.Map{
"page" : gview.HTML(pageContent(page)),
"page" : gview.HTML(content),
})
r.Response.Write(buffer)
})

View File

@ -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" : "<li><span",
"/span>" : "/span></li>",
"<a" : "<li><a",
"/a>" : "/a></li>",
})
return "<ul>" + content + "</ul>"
// 自定义分页名称
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(`
<html>
<head>
@ -38,7 +38,7 @@ func main() {
</body>
</html>
`, g.Map{
"page" : gview.HTML(content),
"page" : gview.HTML(pageContent(page)),
})
r.Response.Write(buffer)
})