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

mendersoftware / mender-server / 1902461369

02 Jul 2025 01:23PM UTC coverage: 65.478% (-0.1%) from 65.622%
1902461369

push

gitlab-ci

web-flow
Merge pull request #764 from mendersoftware/MEN-8237

refactor(useradm): Migrate from ant0nie/go-json-rest to gin-gonic/gin

265 of 312 new or added lines in 6 files covered. (84.94%)

36 existing lines in 6 files now uncovered.

32157 of 49111 relevant lines covered (65.48%)

1.39 hits per line

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

82.35
/backend/pkg/requestid/utils.go
1
// Copyright 2023 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
package requestid
15

16
import (
17
        "context"
18
        "net/http"
19

20
        "github.com/ant0ine/go-json-rest/rest"
21
)
22

23
type requestIdKeyType int
24

25
const (
26
        requestIdKey requestIdKeyType = 0
27
)
28

29
// GetReqId helper for retrieving current request Id
UNCOV
30
func GetReqId(r *http.Request) string {
×
UNCOV
31
        return FromContext(r.Context())
×
UNCOV
32
}
×
33

34
// SetReqId is a helper for setting request ID in request context
35
func SetReqId(r *rest.Request, reqid string) *rest.Request {
1✔
36
        ctx := WithContext(r.Context(), reqid)
1✔
37
        r.Request = r.Request.WithContext(ctx)
1✔
38
        return r
1✔
39
}
1✔
40

41
// FromContext extracts current request Id from context.Context
42
func FromContext(ctx context.Context) string {
9✔
43
        val := ctx.Value(requestIdKey)
9✔
44
        if v, ok := val.(string); ok {
17✔
45
                return v
8✔
46
        }
8✔
47
        return ""
2✔
48
}
49

50
// WithContext adds request to context `ctx` and returns the resulting context.
51
func WithContext(ctx context.Context, reqid string) context.Context {
9✔
52
        return context.WithValue(ctx, requestIdKey, reqid)
9✔
53
}
9✔
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