This is a creation in Article, where the information may have evolved or changed.
Need to make a page: Just made a method, the example in Beego is too troublesome. Let's get a simple one, on the code.
Pagination method, according to the number of pages passed over, per page, total, returns the contents of the pagination 7 pages before the 1,2,3,4,5 format returned, less than 5 pages return the specific page Func paginator (page, Prepage int, nums Int64) Map[stri ng]interface{} {var firstpage int//Previous page address var lastpage int//Next page address//number of nums per page, and prepage total page count totalpages: = Int (math. Ceil (Float64 (nums)/float64 (prepage))//page total if page > totalpages {page = totalpages}if page <= 0 {page = 1}var p Ages []intswitch {case page >= totalpages-5 && totalpages > 5://Last 5 page start: = totalpages-5 + 1firstpage = page-1lastpage = Int (math. Min (Float64 (totalpages), float64 (page+1))) pages = make ([]int, 5) for I, _: = Range pages {Pages[i] = start + i}case page &G t;= 3 && totalpages > 5:start: = page-3 + 1pages = make ([]int, 5) FirstPage = Page-3for I, _: = Range pages {Pages[i] = start + i}firstpage = page-1lastpage = page + 1default:pages = make ([]int, int (math. Min (5, Float64 (totalpages))))) for I, _: = Range pages {Pages[i] = i + 1}firstpage = Int (math. Max (float64 (1), float64 (page-1))) LastPage = page + 1//Fmt. PRINTLN (pages)}paginatormap: = Make (map[string]interface{}) paginatormap["pages"] = pagespaginatormap["TotalPages"] = totalpagespaginatormap["FirstPage"] = firstpagepaginatormap["lastpage"] = lastpagepaginatormap["currpage"] = Pagereturn Paginatormap}
The HTML is like this
<div class= "AM-CF" > total {{. Totals}} record shared {{. Paginator.totalpages}} page current page {{. Paginator.currpage} } <div class= "Am-fr" > <ul class= "am-pagination" > <li class= "" ><a href= "/clubadmin/ Topics/{{.paginator.firstpage}} ">«</a></li> {{range $index, $page: =. paginator.pages}} <li {{if EQ $.paginator.currpage $page}}class= ' am-active ' {{end}}><a href= '/clubadmin/topics/{{$page}} ">{{$page}}</a></li> {{end}} <li><a href="/clubadmin/topics/{{. Paginator.lastpage}} ">»</a></li> </ul> </div></div>
It's like this in the controller.
Res: = models. Paginator (PA, pre_page, totals) this. data["paginator"] = Res