Commit d760a66e authored by Sander van Harmelen's avatar Sander van Harmelen

Tweak naming and ordering (to match the docs order)

Sorry @Lorac I couldn’t resist 😉
parent f8137824
...@@ -38,13 +38,6 @@ const ( ...@@ -38,13 +38,6 @@ const (
libraryVersion = "0.2.0" libraryVersion = "0.2.0"
defaultBaseURL = "https://gitlab.com/api/v4/" defaultBaseURL = "https://gitlab.com/api/v4/"
userAgent = "go-gitlab/" + libraryVersion userAgent = "go-gitlab/" + libraryVersion
headerNextPage = "X-Next-Page"
headerTotalPages = "X-Total-Pages"
headertotalResults = "X-Total"
headerCurrentPage = "X-Page"
headerPerPage = "X-Per-Page"
headerPrevPage = "X-Prev-Page"
) )
// tokenType represents a token type within GitLab. // tokenType represents a token type within GitLab.
...@@ -498,13 +491,12 @@ type Response struct { ...@@ -498,13 +491,12 @@ type Response struct {
// results. Any or all of these may be set to the zero value for // results. Any or all of these may be set to the zero value for
// responses that are not part of a paginated set, or for which there // responses that are not part of a paginated set, or for which there
// are no additional pages. // are no additional pages.
TotalItems int
NextPage int
PrevPage int
CurrentPage int
PerPage int
TotalPages int TotalPages int
TotalResults int ItemsPerPage int
CurrentPage int
NextPage int
PreviousPage int
} }
// newResponse creates a new Response for the provided http.Response. // newResponse creates a new Response for the provided http.Response.
...@@ -517,28 +509,23 @@ func newResponse(r *http.Response) *Response { ...@@ -517,28 +509,23 @@ func newResponse(r *http.Response) *Response {
// populatePageValues parses the HTTP Link response headers and populates the // populatePageValues parses the HTTP Link response headers and populates the
// various pagination link values in the Response. // various pagination link values in the Response.
func (r *Response) populatePageValues() { func (r *Response) populatePageValues() {
if totalPages := r.Response.Header.Get(headerTotalPages); totalPages != "" { if totalItems := r.Response.Header.Get("X-Total"); totalItems != "" {
r.TotalPages, _ = strconv.Atoi(totalPages) r.TotalItems, _ = strconv.Atoi(totalItems)
} }
if totalPages := r.Response.Header.Get("X-Total-Pages"); totalPages != "" {
if totalResults := r.Response.Header.Get(headertotalResults); totalResults != "" { r.TotalPages, _ = strconv.Atoi(totalPages)
r.TotalResults, _ = strconv.Atoi(totalResults)
} }
if itemsPerPage := r.Response.Header.Get("X-Per-Page"); itemsPerPage != "" {
if nextPage := r.Response.Header.Get(headerNextPage); nextPage != "" { r.ItemsPerPage, _ = strconv.Atoi(itemsPerPage)
r.NextPage, _ = strconv.Atoi(nextPage)
} }
if currentPage := r.Response.Header.Get("X-Page"); currentPage != "" {
if currentPage := r.Response.Header.Get(headerCurrentPage); currentPage != "" {
r.CurrentPage, _ = strconv.Atoi(currentPage) r.CurrentPage, _ = strconv.Atoi(currentPage)
} }
if nextPage := r.Response.Header.Get("X-Next-Page"); nextPage != "" {
if perPage := r.Response.Header.Get(headerPerPage); perPage != "" { r.NextPage, _ = strconv.Atoi(nextPage)
r.PerPage, _ = strconv.Atoi(perPage)
} }
if previousPage := r.Response.Header.Get("X-Prev-Page"); previousPage != "" {
if prevPage := r.Response.Header.Get(headerPrevPage); prevPage != "" { r.PreviousPage, _ = strconv.Atoi(previousPage)
r.PrevPage, _ = strconv.Atoi(prevPage)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment