Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rels := make(map[string]string)
link := header.Get("Link")
if len(link) == 0 {
return rels
}
for _, l := range strings.Split(link, ",") {
l = strings.TrimSpace(l)
segments := strings.Split(l, ";")
if len(segments) < 2 {
continue
}
if !strings.HasPrefix(segments[0], "<") || !strings.HasSuffix(segments[0], ">") {
continue
}
url, err := url.Parse(segments[0][1 : len(segments[0])-1])
if err != nil {
continue
}
for _, segment := range segments[1:] {
switch strings.TrimSpace(segment) {
case `rel="next"`:
rels["next"] = link
case `rel="prev"`:
rels["prev"] = link
case `rel="first"`:
rels["first"] = link
case `rel="last"`:
rels["last"] = link
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.