MCPcopy Create free account
hub / github.com/gogs/gogs / SetLinkHeader

Method SetLinkHeader

internal/context/api.go:73–92  ·  view source on GitHub ↗

SetLinkHeader sets pagination link header by given total number and page size.

(total, pageSize int)

Source from the content-addressed store, hash-verified

71
72// SetLinkHeader sets pagination link header by given total number and page size.
73func (c *APIContext) SetLinkHeader(total, pageSize int) {
74 page := paginater.New(total, pageSize, c.QueryInt("page"), 0)
75 links := make([]string, 0, 4)
76 if page.HasNext() {
77 links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"next\"", conf.Server.ExternalURL, c.Req.URL.Path[1:], page.Next()))
78 }
79 if !page.IsLast() {
80 links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"last\"", conf.Server.ExternalURL, c.Req.URL.Path[1:], page.TotalPages()))
81 }
82 if !page.IsFirst() {
83 links = append(links, fmt.Sprintf("<%s%s?page=1>; rel=\"first\"", conf.Server.ExternalURL, c.Req.URL.Path[1:]))
84 }
85 if page.HasPrevious() {
86 links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"prev\"", conf.Server.ExternalURL, c.Req.URL.Path[1:], page.Previous()))
87 }
88
89 if len(links) > 0 {
90 c.Header().Set("Link", strings.Join(links, ","))
91 }
92}
93
94func APIContexter() macaron.Handler {
95 return func(ctx *Context) {

Callers 2

SearchFunction · 0.80
listIssuesFunction · 0.80

Calls 3

appendFunction · 0.85
HeaderMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected