I have a struct array that I need to paginate on the view end.
This is what my code looks like on the 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}} and {{.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 for solution to paginate this because the results are in the hundreds. The only golang solutions I have come across so far are SQL related. I would highly appreciate a solution for a struct array.
Thank you in advance.
EDIT My back end storage is BoltDB. I get the data on the controller by calling this method
func List(bucket string) []Data{
//Open BoltDB database
Open()
defer Close()
//Use a predefined struct to make an array
d:=make([]Data, 0)
//Fetch and unmarshal data as it is saved in byte form
db.View(func(tx *bolt.Tx) error {
cur := tx.Bucket([]byte(bucket)).Cursor()
for 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 the array of data
return d
}
This array is what I would like to iterate on the view.