Skip to content
/ link Public

A library for parsing link pagination headers.

License

Notifications You must be signed in to change notification settings

tanema/link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Link 🧝

Go Reference

Easily parse and create Link headers for pagination.

Create Link Headers

Easily create link headers for responses to your paginated endpoints.

func handler(w http.ResponseWriter, req http.Request) {
    // ...
    linkHeader := link.NewHeader(map[string]*url.URL{
        "first": firstURL,
        "last": lastURL,
        // if these are nil then they will not be included in the header
        "next": nextURL,
        "prev": prevURL,
    })
    w.WriteHeader("link", linkHeader.String())
    // ...
}

Parse Link Headers for integrating with services.

Easily parse link headers from external services to paginate through results.

func loadUsers(path string) {
    resp, err := http.DefaultClient.Get(path)
    linkHeader, err := link.Parse(resp)
    if next := linkHeader.Next(); next != nil {
        loadUsers(next.URL.String())
    }
}

func main() {
    loadUsers("http://service.com/users")
}

About

A library for parsing link pagination headers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages