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

mendersoftware / reporting / 1337903669

16 May 2024 07:52AM UTC coverage: 85.206% (-0.03%) from 85.235%
1337903669

push

gitlab-ci

web-flow
Merge pull request #199 from kjaskiewiczz/ci-fix

chore: upgrade golang in CI pipeline

2995 of 3515 relevant lines covered (85.21%)

14.21 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) {
35✔
25
        url := &url.URL{
35✔
26
                Path:     c.Request.URL.Path,
35✔
27
                RawQuery: c.Request.URL.RawQuery,
35✔
28
                Fragment: c.Request.URL.Fragment,
35✔
29
        }
35✔
30

35✔
31
        query := url.Query()
35✔
32

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

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

×
50
        }
×
51
        c.Header("Link", Link)
35✔
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