2015-12-10 15:33:58 +01:00
|
|
|
# Golang Link Header Parser
|
|
|
|
|
2022-11-20 21:48:11 +01:00
|
|
|
Forked from "https://github.com/tomnomnom/linkheader"
|
|
|
|
|
2017-05-04 11:43:35 +02:00
|
|
|
Library for parsing HTTP Link headers. Requires Go 1.6 or higher.
|
2015-12-10 15:33:58 +01:00
|
|
|
|
2016-03-28 18:20:06 +02:00
|
|
|
Docs can be found on [the GoDoc page](https://godoc.org/github.com/tomnomnom/linkheader).
|
2015-12-10 15:43:51 +01:00
|
|
|
|
|
|
|
## Basic Example
|
2015-12-10 15:33:58 +01:00
|
|
|
|
|
|
|
```go
|
2015-12-10 19:53:34 +01:00
|
|
|
package main
|
2015-12-10 15:51:28 +01:00
|
|
|
|
2015-12-10 19:53:34 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
2015-12-10 15:33:58 +01:00
|
|
|
|
2022-11-20 21:48:11 +01:00
|
|
|
linkheader "git.gutmet.org/linkheader.git"
|
2015-12-10 19:53:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2015-12-10 15:33:58 +01:00
|
|
|
}
|
2015-12-10 15:43:51 +01:00
|
|
|
|
|
|
|
// 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
|
2015-12-10 15:33:58 +01:00
|
|
|
```
|