This is a creation in Article, where the information may have evolved or changed.
A paging function translated from PHP, can be used! The code writes more rubbish, and then the time is improved.
Package Mainimport ("bytes" "FMT" "Math" "OS" "StrConv" "strings") func main () {var html stringhtml = multi (3, "http:/ /xxoo.io ") UserFile: =" Log.html "Fout, _: = OS. Create (UserFile) fmt. PRINTLN (HTML) fout. WriteString (HTML) fout. Close ()}func multi (num int, perpage int, curpage int, url string) string {var (mpurl stringfrom Intto Int//ret *byte S.buffer = new (bytes. Buffer) ret bytes. Buffer = bytes. buffer{}) if strings. Index (URL, "?")! =-1 {mpurl = URL + "&"} else {mpurl = URL + "?;"} If num > perpage {page: = 10offset: = 5pages: = Int (math. Ceil (Float64 (num/perpage))) if page > pages {from = 1to = pages} else {from = Curpage-offsetto = curpage + page + of Fset-1if from < 1 {to = curpage + 1-fromfrom = 1if (to-from) < page && (To-from) < pages {to = page}} else if to > pages {from = curpage-pages + Toto = pagesif (to-from) < page && (To-from) < pages {from = Pages-page + 1}}}if (curpage-offset) > 1 && pages > page {ret. WRitestring ("<a href=\" "+ Mpurl +" page=1\ "class=\" p_redirect\ ">«</a>")}if curpage > 1 {ret. WriteString ("<a href=\" "+ Mpurl +" page= "+ StrConv. Itoa (curpage-1) + "\" class=\ "p_redirect\" >‹</a> ")}for I: = from; I <= to; i++ {if i = = curpage {ret. WriteString ("<span class=\" p_curpage\ ">" + StrConv. Itoa (i) + "</span>")} else {ret. WriteString ("<a href=\" "+ Mpurl +" page= "+ StrConv. Itoa (i) + "\" class=\ "p_num\" > "+ StrConv. Itoa (i) + "</a>")}}if Curpage < pages {ret. WriteString ("<a href=\" "+ Mpurl +" page= "+ StrConv. Itoa (curpage+1) + "\" class=\ "p_redirect\" >›</a> ")}if to < pages {ret. WriteString ("<a href=\" "+ Mpurl +" page= "+ StrConv. Itoa (pages) + "\" class=\ "p_redirect\" >»</a> ")}if ret. Len () > 0 {return "<div class=\" p_bar\ "><span class=\" p_info\ ">records:" + StrConv. Itoa (num) + "</span>" + ret. String () + "</div>"}}return ""}/*function multi ($num, $perpage, $curpage, $mpurl{$multipage = "; $mpurl. = Strpos ($mpurl, '? ')? ' & ': '? '; if ($num > $perpage) {$page = ten; $offset = 5; $pages = @ceil ($num/$perpage), if ($page > $pages) {$from = 1; $to = $pag es;} else {$from = $curpage-$offset; $to = $curpage + $page-$offset -1;if ($from < 1) {$to = $curpage + 1-$from; $from = 1;if (($to-$from) < $page && ($to-$from) < $pages) {$to = $page;}} ElseIf ($to > $pages) {$from = $curpage-$pages + $to; $to = $pages; if ($to-$from) < $page && ($to-$from) < $pages) {$from = $pages-$page + 1;}}} $multipage = ($curpage-$offset > 1 && $pages > $page? ' <a href= '. $mpurl. ' page=1 ' class= "P_redirect" >«</a> ': '). ($curpage > 1? ' <a href= '. $mpurl. ' Page= '. ($curpage-1). ' " class= "P_redirect" >‹</a> ': '); for ($i = $from; $i <= $to; $i + +) {$multipage. = $i = = $curpage? ' <span class= ' p_curpage > ' $i. ' </span> ': ' <a href= '. $mpurl. ' page= '. $i. ' class= ' p_num ' > '. $i. ' </a> ';} $multipage. = ($curpage < $pages? ' <a href= '. $mpurl. ' Page= '. ($curpage + 1). ' " class= "P_redirect" >›</a> ': '). ($to < $pages? ' <a href= '. $mpurl. ' page= ' $pages. ' class= ' p_redirect ' >»</a> ': '; $multipage = $multipage? ' <div class= ' P_bar "><span class=" P_info ">records: '. $num. ' </span> ' $multipage. ' </div> ': ';} return $multipage;} */