• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.travis.ymlH A D24-Jan-201893

LICENSEH A D24-Jan-20181.1 KiB

README.mdH A D24-Jan-20183.5 KiB

doc.goH A D24-Jan-20181 KiB

link.goH A D24-Jan-20182.3 KiB

link_test.goH A D24-Jan-20187.7 KiB

README.md

1# link
2
3[![Build Status](https://travis-ci.org/peterhellberg/link.svg?branch=master)](https://travis-ci.org/peterhellberg/link)
4[![Go Report Card](https://goreportcard.com/badge/github.com/peterhellberg/link)](https://goreportcard.com/report/github.com/peterhellberg/link)
5[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/peterhellberg/link)
6[![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/peterhellberg/link#license-mit)
7
8Parses **Link** headers used for pagination, as defined in [RFC 5988](https://tools.ietf.org/html/rfc5988).
9
10This package was originally based on <https://github.com/swhite24/link>, but **Parse** takes a `string` instead of `*http.Request` in this version.
11It also has the convenience functions **ParseHeader**, **ParseRequest** and **ParseResponse**.
12
13## Installation
14
15    go get -u github.com/peterhellberg/link
16
17## Exported functions
18
19 - [Parse(s string) Group](https://godoc.org/github.com/peterhellberg/link#Parse)
20 - [ParseHeader(h http.Header) Group](https://godoc.org/github.com/peterhellberg/link#ParseHeader)
21 - [ParseRequest(req \*http.Request) Group](https://godoc.org/github.com/peterhellberg/link#ParseRequest)
22 - [ParseResponse(resp \*http.Response) Group](https://godoc.org/github.com/peterhellberg/link#ParseResponse)
23
24## Usage
25
26```go
27package main
28
29import (
30	"fmt"
31	"net/http"
32
33	"github.com/peterhellberg/link"
34)
35
36func main() {
37	for _, l := range link.Parse(`<https://example.com/?page=2>; rel="next"; foo="bar"`) {
38		fmt.Printf("URI: %q, Rel: %q, Extra: %+v\n", l.URI, l.Rel, l.Extra)
39		// URI: "https://example.com/?page=2", Rel: "next", Extra: map[foo:bar]
40	}
41
42	if resp, err := http.Get("https://api.github.com/search/code?q=Println+user:golang"); err == nil {
43		for _, l := range link.ParseResponse(resp) {
44			fmt.Printf("URI: %q, Rel: %q, Extra: %+v\n", l.URI, l.Rel, l.Extra)
45			// URI: "https://api.github.com/search/code?q=Println+user%3Agolang&page=2", Rel: "next", Extra: map[]
46			// URI: "https://api.github.com/search/code?q=Println+user%3Agolang&page=34", Rel: "last", Extra: map[]
47		}
48	}
49}
50```
51
52## Not supported
53
54 - Extended notation ([RFC 5987](https://tools.ietf.org/html/rfc5987))
55
56## Alternatives to this package
57
58 - [github.com/tent/http-link-go](https://github.com/tent/http-link-go)
59 - [github.com/swhite24/link](https://github.com/swhite24/link)
60
61## License (MIT)
62
63Copyright (c) 2015-2017 [Peter Hellberg](https://c7.se/)
64
65> Permission is hereby granted, free of charge, to any person obtaining
66> a copy of this software and associated documentation files (the
67> "Software"), to deal in the Software without restriction, including
68> without limitation the rights to use, copy, modify, merge, publish,
69> distribute, sublicense, and/or sell copies of the Software, and to
70> permit persons to whom the Software is furnished to do so, subject to
71> the following conditions:
72
73> The above copyright notice and this permission notice shall be
74> included in all copies or substantial portions of the Software.
75
76> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
77> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
78> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
79> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
80> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
81> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
82> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
83