• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / reporting / 757363348

pending completion
757363348

push

gitlab-ci

GitHub
Merge pull request #92 from mendersoftware/master

916 of 1037 new or added lines in 19 files covered. (88.33%)

5 existing lines in 3 files now uncovered.

2733 of 3187 relevant lines covered (85.75%)

17.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.77
/api/http/utils.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package http
16

17
import (
18
        "fmt"
19
        "net/url"
20

21
        "github.com/gin-gonic/gin"
22
)
23

24
func pageLinkHdrs(c *gin.Context, page, perPage, total int) {
25
        url := &url.URL{
26
                Path:     c.Request.URL.Path,
27
                RawQuery: c.Request.URL.RawQuery,
28
                Fragment: c.Request.URL.Fragment,
29
        }
30

31
        query := url.Query()
32

33
        query.Set("page", "1")
34
        query.Set("per_page", fmt.Sprintf("%d", perPage))
35
        url.RawQuery = query.Encode()
36
        Link := fmt.Sprintf(`<%s>;rel="first"`, url.String())
37
        // Previous page
38
        if page > 1 {
39
                query.Set("page", fmt.Sprintf("%d", page-1))
40
                url.RawQuery = query.Encode()
41
                Link = fmt.Sprintf(`%s, <%s>;rel="previous"`, Link, url.String())
42
        }
43

44
        // Next page
45
        if total > (perPage*page - 1) {
NEW
46
                query.Set("page", fmt.Sprintf("%d", page+1))
NEW
47
                url.RawQuery = query.Encode()
NEW
48
                Link = fmt.Sprintf(`%s, <%s>;rel="next"`, Link, url.String())
NEW
49

NEW
50
        }
51
        c.Header("Link", Link)
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc