Documentation ¶
Overview ¶
Package linkheader provides functions for parsing HTTP Link headers
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Link ¶
A Link is a single URL and related parameters
func (Link) String ¶
String returns the string representation of a link
Example ¶
package main import ( "fmt" "github.com/tomnomnom/linkheader" ) func main() { link := linkheader.Link{ URL: "http://example.com/page/2", Rel: "next", } fmt.Printf("Link: %s\n", link.String()) }
Output: Link: <http://example.com/page/2>; rel="next"
type Links ¶
type Links []Link
Links is a slice of Link structs
func Parse ¶
Parse parses a raw Link header in the form:
<url>; rel="foo", <url>; rel="bar"; wat="dis"
returning a slice of Link structs
Example ¶
package main import ( "fmt" "github.com/tomnomnom/linkheader" ) func main() { header := "<https://api.github.com/user/58276/repos?page=2>; rel=\"next\"," + "<https://api.github.com/user/58276/repos?page=2>; rel=\"last\"" links := linkheader.Parse(header) for _, link := range links { fmt.Printf("URL: %s; Rel: %s\n", link.URL, link.Rel) } }
Output: URL: https://api.github.com/user/58276/repos?page=2; Rel: next URL: https://api.github.com/user/58276/repos?page=2; Rel: last
func ParseMultiple ¶
ParseMultiple is like Parse, but accepts a slice of headers rather than just one header string
Example ¶
package main import ( "fmt" "github.com/tomnomnom/linkheader" ) func main() { headers := []string{ "<https://api.github.com/user/58276/repos?page=2>; rel=\"next\"", "<https://api.github.com/user/58276/repos?page=2>; rel=\"last\"", } links := linkheader.ParseMultiple(headers) for _, link := range links { fmt.Printf("URL: %s; Rel: %s\n", link.URL, link.Rel) } }
Output: URL: https://api.github.com/user/58276/repos?page=2; Rel: next URL: https://api.github.com/user/58276/repos?page=2; Rel: last
func (Links) FilterByRel ¶
FilterByRel filters a group of Links by the provided Rel attribute
Example ¶
package main import ( "fmt" "github.com/tomnomnom/linkheader" ) func main() { header := "<https://api.github.com/user/58276/repos?page=2>; rel=\"next\"," + "<https://api.github.com/user/58276/repos?page=2>; rel=\"last\"" links := linkheader.Parse(header) for _, link := range links.FilterByRel("last") { fmt.Printf("URL: %s; Rel: %s\n", link.URL, link.Rel) } }
Output: URL: https://api.github.com/user/58276/repos?page=2; Rel: last
func (Links) String ¶
String returns the string representation of multiple Links for use in HTTP responses etc
Example ¶
package main import ( "fmt" "github.com/tomnomnom/linkheader" ) func main() { links := linkheader.Links{ {URL: "http://example.com/page/3", Rel: "next"}, {URL: "http://example.com/page/1", Rel: "last"}, } fmt.Printf("Link: %s\n", links.String()) }
Output: Link: <http://example.com/page/3>; rel="next", <http://example.com/page/1>; rel="last"
Click to show internal directories.
Click to hide internal directories.