github.com/nesv/gothub@v0.0.0-20140406181320-f0c824044d5f/httputil.go (about)

     1  package gothub
     2  
     3  import (
     4  	"net/http"
     5  	"regexp"
     6  	"strings"
     7  )
     8  
     9  var (
    10  	linkRegex = regexp.MustCompile(`^<(?P<url>https?:\/\/[^>]+)>;\s+rel="(?P<rel>next|last|first|prev)"$`)
    11  )
    12  
    13  type httpLink struct {
    14  	Url string
    15  	Rel string
    16  }
    17  
    18  func parseLinkHeader(response *http.Response) (links []*httpLink) {
    19  	locations := strings.Split(response.Header.Get("Link"), ",")
    20  	for _, v := range locations {
    21  		matches := linkRegex.FindStringSubmatch(strings.Trim(v, " "))
    22  		link := &httpLink{Url: matches[1], Rel: matches[2]}
    23  		links = append(links, link)
    24  	}
    25  	return
    26  }