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

mendersoftware / mender-server / 1899590412

01 Jul 2025 09:26AM UTC coverage: 65.694% (-0.04%) from 65.731%
1899590412

push

gitlab-ci

bahaa-ghazal
refactor: Remove unused ant0ine/go-json-rest utilities from deployments

Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>

32420 of 49350 relevant lines covered (65.69%)

1.39 hits per line

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

93.02
/backend/services/deployments/utils/restutil/view/view.go
1
// Copyright 2021 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 view
16

17
import (
18
        "errors"
19
        "fmt"
20
        "net/http"
21
        "strings"
22

23
        "github.com/gin-gonic/gin"
24

25
        "github.com/mendersoftware/mender-server/pkg/rest.utils"
26

27
        "github.com/mendersoftware/mender-server/services/deployments/model"
28
)
29

30
// Headers
31
const (
32
        HttpHeaderLocation = "Location"
33
)
34

35
// Errors
36
var (
37
        ErrNotFound = errors.New("Resource not found")
38
)
39

40
type RESTView struct {
41
}
42

43
func (p *RESTView) RenderSuccessPost(c *gin.Context, id string) {
3✔
44
        c.Writer.Header().Add(
3✔
45
                HttpHeaderLocation,
3✔
46
                fmt.Sprintf("%s/%s", c.Request.URL.Path, id),
3✔
47
        )
3✔
48
        c.Status(http.StatusCreated)
3✔
49
}
3✔
50

51
func (p *RESTView) RenderSuccessGet(c *gin.Context, object interface{}) {
3✔
52
        c.JSON(http.StatusOK, object)
3✔
53
}
3✔
54

55
func (p *RESTView) RenderError(
56
        c *gin.Context,
57
        err error,
58
        status int,
59
) {
2✔
60
        rest.RenderError(c, status, err)
2✔
61
}
2✔
62

63
func (p *RESTView) RenderInternalError(
64
        c *gin.Context,
65
        err error,
66
) {
×
67
        rest.RenderInternalError(c, err)
×
68
}
×
69

70
func (p *RESTView) RenderErrorNotFound(c *gin.Context) {
3✔
71
        rest.RenderError(c, http.StatusNotFound, ErrNotFound)
3✔
72
}
3✔
73

74
func (p *RESTView) RenderSuccessDelete(c *gin.Context) {
2✔
75
        c.Status(http.StatusNoContent)
2✔
76
}
2✔
77

78
func (p *RESTView) RenderSuccessPut(c *gin.Context) {
1✔
79
        c.Status(http.StatusNoContent)
1✔
80
}
1✔
81

82
func (p *RESTView) RenderNoUpdateForDevice(c *gin.Context) {
3✔
83
        p.RenderEmptySuccessResponse(c)
3✔
84
}
3✔
85

86
// Success response with no data aka. 204 No Content
87
func (p *RESTView) RenderEmptySuccessResponse(c *gin.Context) {
3✔
88
        c.Status(http.StatusNoContent)
3✔
89
}
3✔
90

91
func (p *RESTView) RenderDeploymentLog(c *gin.Context, dlog model.DeploymentLog) {
2✔
92
        h := c.Writer
2✔
93

2✔
94
        h.Header().Set("Content-Type", "text/plain")
2✔
95
        h.WriteHeader(http.StatusOK)
2✔
96

2✔
97
        for _, m := range dlog.Messages {
4✔
98
                as := m.String()
2✔
99
                _, _ = h.Write([]byte(as))
2✔
100
                if !strings.HasSuffix(as, "\n") {
4✔
101
                        _, _ = h.Write([]byte("\n"))
2✔
102
                }
2✔
103
        }
104
}
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