go - Golang Revel: Paginating a struct array -


i have struct array need paginate on view end.

this code looks on view:

<div class="tab-content">         <div class="tab-pane active" id="tab1" >           <hr/>           {{range .c}}                             <p>number: {{.number}}</p>             <p>name: {{.name}}</p>             <p>parties: {{.a}} , {{.b}}</p>             <p>location: {{.location}}</p>           <a href="/search">read more</a>           <hr/>           {{end}}           <div class="paging">             <ul class="pagination">               <li><a href="#"><i class="fa fa-angle-left"></i></a></li>               <li class="active"><a href="#">1</a></li>               <li><a href="#">2</a></li>               <li><a href="#">3</a></li>               <li><a href="#">4</a></li>               <li><a href="#">5</a></li>               <li><a href="#"><i class="fa fa-angle-right"></i></a></li>             </ul>           </div>         </div> 

i have tried looking solution paginate because results in hundreds. golang solutions have come across far sql related. highly appreciate solution struct array.

thank in advance.

edit end storage boltdb. data on controller calling method

func list(bucket string)  []data{     //open boltdb database     open()     defer close()     //use predefined struct make array     d:=make([]data, 0)     //fetch , unmarshal data saved in byte form     db.view(func(tx *bolt.tx) error {         cur := tx.bucket([]byte(bucket)).cursor()         k, v := cur.first(); k != nil; k, v = cur.next() {                         d1:=data{}             err:= json.unmarshal(v, &d1)             if err !=nil{                 return err             }             d=append(d, d1)         }          return nil       })     //return array of data     return d } 

this array iterate on view.

you collect full array of data return list function.

func paginate(x []data, skip int, size int) []int { limit := func() int {     if skip+size > len(x) {         return len(x)     } else {         return skip + size     }  }  start := func() int {     if skip > len(x) {         return len(x)     } else {         return skip     }  }   return x[start():limit()] } 

although behavior want, wasteful in terms of memory specially if data array huge. hope helps.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -