doc.go raw

   1  /*
   2  Package link parses Link headers used for pagination, as defined in RFC 5988
   3  
   4  # Installation
   5  
   6  Just go get the package:
   7  
   8  	go get -u github.com/peterhellberg/link
   9  
  10  # Usage
  11  
  12  A small usage example
  13  
  14  	package main
  15  
  16  	import (
  17  		"fmt"
  18  		"net/http"
  19  
  20  		"github.com/peterhellberg/link"
  21  	)
  22  
  23  	func main() {
  24  		for _, l := range link.Parse(`<https://example.com/?page=2>; rel="next"; foo="bar"`) {
  25  			fmt.Printf("URI: %q, Rel: %q, Extra: %+v\n", l.URI, l.Rel, l.Extra)
  26  			// URI: "https://example.com/?page=2", Rel: "next", Extra: map[foo:bar]
  27  		}
  28  
  29  		if resp, err := http.Get("https://api.github.com/search/code?q=Println+user:golang"); err == nil {
  30  			for _, l := range link.ParseResponse(resp) {
  31  				fmt.Printf("URI: %q, Rel: %q, Extra: %+v\n", l.URI, l.Rel, l.Extra)
  32  				// URI: "https://api.github.com/search/code?q=Println+user%3Agolang&page=2", Rel: "next", Extra: map[]
  33  				// URI: "https://api.github.com/search/code?q=Println+user%3Agolang&page=34", Rel: "last", Extra: map[]
  34  			}
  35  		}
  36  	}
  37  */
  38  package link
  39