github.com/zhongdalu/gf@v1.0.0/geg/util/gpage/gpage_custom2.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/zhongdalu/gf/g"
     5  	"github.com/zhongdalu/gf/g/net/ghttp"
     6  	"github.com/zhongdalu/gf/g/os/gview"
     7  	"github.com/zhongdalu/gf/g/util/gpage"
     8  )
     9  
    10  // 自定义分页名称
    11  func pageContent(page *gpage.Page) string {
    12  	page.NextPageTag = "NextPage"
    13  	page.PrevPageTag = "PrevPage"
    14  	page.FirstPageTag = "HomePage"
    15  	page.LastPageTag = "LastPage"
    16  	pageStr := page.FirstPage()
    17  	pageStr += page.PrevPage()
    18  	pageStr += page.PageBar("current-page")
    19  	pageStr += page.NextPage()
    20  	pageStr += page.LastPage()
    21  	return pageStr
    22  }
    23  
    24  func main() {
    25  	s := ghttp.GetServer()
    26  	s.BindHandler("/page/custom2/*page", func(r *ghttp.Request) {
    27  		page := gpage.New(100, 10, r.Get("page"), r.URL.String(), r.Router)
    28  		buffer, _ := gview.ParseContent(`
    29          <html>
    30              <head>
    31                  <style>
    32                      a,span {padding:8px; font-size:16px;}
    33                      div{margin:5px 5px 20px 5px}
    34                  </style>
    35              </head>
    36              <body>
    37                  <div>{{.page}}</div>
    38              </body>
    39          </html>
    40          `, g.Map{
    41  			"page": pageContent(page),
    42  		})
    43  		r.Response.Write(buffer)
    44  	})
    45  	s.SetPort(10000)
    46  	s.Run()
    47  }