pagination.go raw

   1  package desec
   2  
   3  import (
   4  	"net/http"
   5  	"net/url"
   6  
   7  	"github.com/peterhellberg/link"
   8  )
   9  
  10  // Cursors allows to retrieve the next (or previous) page.
  11  // https://desec.readthedocs.io/en/latest/dns/rrsets.html#pagination
  12  type Cursors struct {
  13  	First string
  14  	Prev  string
  15  	Next  string
  16  }
  17  
  18  func parseCursor(h http.Header) (*Cursors, error) {
  19  	links := link.ParseHeader(h)
  20  
  21  	c := &Cursors{}
  22  
  23  	for s, l := range links {
  24  		uri, err := url.ParseRequestURI(l.URI)
  25  		if err != nil {
  26  			return nil, err
  27  		}
  28  
  29  		query := uri.Query()
  30  
  31  		switch s {
  32  		case "first":
  33  			c.First = query.Get("cursor")
  34  		case "prev":
  35  			c.Prev = query.Get("cursor")
  36  		case "next":
  37  			c.Next = query.Get("cursor")
  38  		}
  39  	}
  40  
  41  	return c, nil
  42  }
  43