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

mendersoftware / reporting / 820253733

pending completion
820253733

Pull #125

gitlab-ci

GitHub
Merge pull request #124 from kjaskiewiczz/men-6405
Pull Request #125: align staging with master

11 of 20 new or added lines in 4 files covered. (55.0%)

5 existing lines in 3 files now uncovered.

2815 of 3311 relevant lines covered (85.02%)

17.51 hits per line

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

83.33
/app/server/server.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 server
16

17
import (
18
        "context"
19
        "net/http"
20
        "os"
21
        "os/signal"
22
        "time"
23

24
        "golang.org/x/sys/unix"
25

26
        "github.com/gin-gonic/gin"
27

28
        "github.com/mendersoftware/go-lib-micro/config"
29
        "github.com/mendersoftware/go-lib-micro/log"
30

31
        api "github.com/mendersoftware/reporting/api/http"
32
        "github.com/mendersoftware/reporting/app/reporting"
33
        dconfig "github.com/mendersoftware/reporting/config"
34
        "github.com/mendersoftware/reporting/store"
35
)
36

37
func init() {
4✔
38
        if mode := os.Getenv(gin.EnvGinMode); mode != "" {
4✔
39
                gin.SetMode(mode)
×
40
        } else {
4✔
41
                gin.SetMode(gin.ReleaseMode)
4✔
42
        }
4✔
43
}
44

45
// InitAndRun initializes the server and runs it
46
func InitAndRun(conf config.Reader, store store.Store, ds store.DataStore) error {
1✔
47
        ctx := context.Background()
1✔
48

1✔
49
        l := log.FromContext(ctx)
1✔
50

1✔
51
        reporting := reporting.NewApp(store, ds)
1✔
52

1✔
53
        var listen = conf.GetString(dconfig.SettingListen)
1✔
54
        var router = api.NewRouter(reporting)
1✔
55
        srv := &http.Server{
1✔
56
                Addr:    listen,
1✔
57
                Handler: router,
1✔
58
        }
1✔
59

1✔
60
        go func() {
2✔
61
                if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
1✔
62
                        l.Fatalf("listen: %s\n", err)
×
63
                }
×
64
        }()
65

66
        quit := make(chan os.Signal, 1)
1✔
67
        signal.Notify(quit, unix.SIGINT, unix.SIGTERM)
1✔
68
        <-quit
1✔
69

1✔
70
        l.Info("Shutdown Server ...")
1✔
71

1✔
72
        ctxWithTimeout, cancel := context.WithTimeout(ctx, 5*time.Second)
1✔
73
        defer cancel()
1✔
74
        if err := srv.Shutdown(ctxWithTimeout); err != nil {
1✔
75
                l.Fatal("Server Shutdown: ", err)
×
76
        }
×
77

UNCOV
78
        return nil
×
79
}
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