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

mendersoftware / reporting / 1080732370

12 Nov 2023 09:07AM UTC coverage: 88.965% (-0.04%) from 89.001%
1080732370

push

gitlab-ci

web-flow
Merge pull request #174 from mendersoftware/dependabot/go_modules/golang.org/x/net-0.18.0

chore: bump golang.org/x/net from 0.15.0 to 0.18.0

2467 of 2773 relevant lines covered (88.97%)

18.1 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() {
3✔
38
        if mode := os.Getenv(gin.EnvGinMode); mode != "" {
3✔
39
                gin.SetMode(mode)
×
40
        } else {
3✔
41
                gin.SetMode(gin.ReleaseMode)
3✔
42
        }
3✔
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

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